Jay Blanchard | 1 Feb 01:10 2007

RE: PHP equivalent to Perl $0

[snip]
In Perl there is the predefined $0 which contains the name of the file
containing the Perl script being executed. Is there an equivalent in
PHP?
[/snip]

$_SERVER['PHP_SELF']

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Kevin Jordan | 1 Feb 01:12 2007
Picon

Re: PHP equivalent to Perl $0

On 1/31/07, Richard Luckhurst <rluckhurst <at> resmaster.com> wrote:
> Hi
>
> In Perl there is the predefined $0 which contains the name of the file
> containing the Perl script being executed. Is there an equivalent in PHP?
>
> I am working on converting a Listener script from Perl to PHP and at one point
> when the script forks it has a line
>
> $0 = "Listener is accepting connections on Port $port";
>
> When this Perl script is running and I do a ps I see a process ID with the
> program being
>
> Listener is accepting connections on Port $port
>
> instead of the actual name of the Perl script.
>
> Is such a thing possible in PHP? If so how? I have been Google searching for a
> while and can not see one way or the other if it is possible.
>
>
>
> Regards,
> Richard Luckhurst
> Product Development
> Exodus Systems - Sydney, Australia.
>
> --
> PHP General Mailing List (http://www.php.net/)
(Continue reading)

Chris | 1 Feb 01:14 2007
Picon

Re: PHP equivalent to Perl $0

Jay Blanchard wrote:
> [snip]
> In Perl there is the predefined $0 which contains the name of the file
> containing the Perl script being executed. Is there an equivalent in
> PHP?
> [/snip]
> 
> $_SERVER['PHP_SELF']

Or if you're using it from the command line, $argv[0]

-- 
Postgresql & php tutorials
http://www.designmagick.com/

--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

jekillen | 1 Feb 01:13 2007
Picon
Picon

Re: ereg() problem


On Jan 31, 2007, at 8:13 AM, Jim Lucas wrote:

> jekillen wrote:
>> Hello php list;
>> I am having trouble with ereg().
>> The following is the problem code
>> $x = ereg("<route name='$to' x='../(.*)/in' rec='.*' />", $get_route, 
>> $m);
> do we need to break out of the text to include the $to variable??
The $to variable is what I use to id the tag to get the path from, it is
critical. It is like answering the question 'What is Joe's address?'
Joe in this example is the $to variable.

>
>> testing $route I get:
> do you mean $get_route?
No, I mean $route after I have assigned $m[1] to it;
>
>> $route = $m[1];
>> print $route.'<br>';
>> jk/in' rec='a_378e6dc4.xml' /> (out put of print)
> Is this an example of th input?
This is what the regular expression (.*) is matching
in the tag. It will have a steadily increasing number
of tags in the above pattern and nothing else (accept
for opening and closing xml tags.
>
> What does an actual line of $get_route look like?
$get_route is what was read from the XML file.
(Continue reading)

Richard Lynch | 1 Feb 01:24 2007

Re: PHP equivalent to Perl $0

On Wed, January 31, 2007 5:59 pm, Richard Luckhurst wrote:
> In Perl there is the predefined $0 which contains the name of the file
> containing the Perl script being executed. Is there an equivalent in
> PHP?

$_SERVER['PHP_SELF']

> I am working on converting a Listener script from Perl to PHP and at
> one point
> when the script forks it has a line
>
> $0 = "Listener is accepting connections on Port $port";
>
> When this Perl script is running and I do a ps I see a process ID with
> the
> program being
>
> Listener is accepting connections on Port $port
>
> instead of the actual name of the Perl script.
>
> Is such a thing possible in PHP? If so how? I have been Google
> searching for a
> while and can not see one way or the other if it is possible.

I have no idea if you can cram some whack value into that and then ps
would show that instead of the path...  I doubt it.

And, frankly, why would you want to do that?  It only sows confusion
in ps output. :-)
(Continue reading)

Richard Luckhurst | 1 Feb 01:32 2007

Re[2]: PHP equivalent to Perl $0

Hi Richard,

RL> And, frankly, why would you want to do that?  It only sows confusion
RL> in ps output. :-)

I happen to agree with you. Why would you want to do it. The reason it is being
done in this application is to keep a specification for he application happy.

When the php program is executing and you do a ps you see

/usr/local/bin/php -q listener.php

which is perfectly fine by me :-)

What happens with the Perl application beacuse of stuffing the string back into
the $0 is that you see

Listener is accepting connections on Port 15556

It seems to me that whoever wrote the specification had this thing about ps
showing a nice string instead of the program name actually running. Of course I
know that this is what ps is supposed to do and Perl allows you to tell nice
lies to ps :-)

Regards,
Richard Luckhurst
Product Development
Exodus Systems - Sydney, Australia.
rluckhurst <at> resmaster.com

(Continue reading)

Richard Lynch | 1 Feb 01:38 2007

Re: ereg() problem

On Tue, January 30, 2007 8:36 pm, jekillen wrote:
> I am having trouble with ereg().
> The following is the problem code
> $x = ereg("<route name='$to' x='../(.*)/in' rec='.*' />", $get_route,
> $m);
> testing $route I get:
> $route = $m[1];
> print $route.'<br>';
> jk/in' rec='a_378e6dc4.xml' /> (out put of print)
> jk is all I am looking for but
> is it greed that is missing the
> forward slash and the single quote?

No, it's that you put the parens () around only the .* and not around
what you wanted:
ereg("<route name='$to' x='\\.\\.(.*/in') rec='.*' />", ...

> It seems like every time I do this I have to monkey around
> with it until I get what I want.

Join the club. :-)

You may want to consider a couple actions:
  Switch to PCRE http://php.net/pcre

It's better documented, less confusing, faster, and just better all
around.

Download and play around with "The Regex Coach" which provides a
visual feedback on what happens when you change the #$^%& inside your
(Continue reading)

Mark Charette | 1 Feb 01:42 2007

Re: PHP equivalent to Perl $0

Richard Luckhurst wrote:
> Hi Richard,
> 
> 
> RL> And, frankly, why would you want to do that?  It only sows confusion
> RL> in ps output. :-)

Unless you're talking about apps spawned by inetd and its cousins. ps 
shows the name as specified in arguments in the inetd.conf file, not the 
name of the executable, which often prefixed by "in." , to indicate it's 
supposed to be spawned by inetd.

> It seems to me that whoever wrote the specification had this thing about ps
> showing a nice string instead of the program name actually running. Of course I
> know that this is what ps is supposed to do and Perl allows you to tell nice
> lies to ps :-)

As does C, C++, and a host of other languages. PHP does not - even 
though there's no error when you stuff a CLI php's $argv[0] with a 
different name:
#!/usr/local/bin/php
<?php
$argv[0]="whatever";
sleep(20);
?>

./qq.php &

ps

(Continue reading)

Richard Lynch | 1 Feb 02:04 2007

Re: Select record by ID

On Tue, January 30, 2007 4:14 pm, nitrox . wrote:
> Richard, ive included your suggested code and now my php script is
> working
> properly. But I dont want to be a php copy/paste newb who has no clue
> of how
> things are working. If its not too much would you (or anybody) give a
> brief
> explanation of what this code is doing? Or are there any tutorials
> online
> that I can read that will educate me on this? Thanks again to all for
> your
> replies. Ive saved them all for future reference.
>
> atleast this part: $user_id = mysql_real_escape_string((int)
> $_GET['user_id']);

$_GET is an array which has all the values from the URL.

For example, this URL:
http://example.com/yourscript.php?user_id=42
would cause PHP to pre-build this for you:
$_GET['user_id'] = 42;

If you didn't care about SECURITY, you could just do:
$user_id = $_GET['user_id'];
and go on your merry way.

All the rest of the stuff is about SECURITY.

Bad Guys know that you are probably using that user_id in an SQL
(Continue reading)

Richard Lynch | 1 Feb 02:08 2007

Re: Select record by ID

On Tue, January 30, 2007 7:23 pm, Craige Leeder wrote:
>> atleast this part: $user_id = mysql_real_escape_string((int)
>> $_GET['user_id']);
>
> I'm not sure who put this in there, but you don't need to use
> mysql_real_escape_string() on that value if you're type casting it. If
> you are forcing it to be an integer, there is nothing to escape.
> Integers are perfectly fine to be put into a query as they are.

Can you guarantee that in every character encoding, past, present, and
future?...

Before you answer, keep in mind that the '-' sign is part of an (int).

I'm not claiming that there is any real danger -- only that there is
the theoretical possibility, and skimping on a
mysql_real_escape_string() call is not the right thing to do.

Actually, all I really wanted to do with that was to be sure that the
OP did *something* to learn more about the security issues of user
input and SQL injection attacks...  Didn't expect it to engender this
much discussion, but there it is.

--

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

(Continue reading)


Gmane