Connecting Tech Pros Worldwide Help | Site Map

PSP_SELF

Buck Turgidson
Guest
 
Posts: n/a
#1: Jul 17 '05
I am trying to learn PHP. I am confused as to why I need
$_SERVER['PHP_SELF'] in the first block, but just $PHP_SELF in the 2nd. I
don't see the latter assigned anywhere in the code.

Thanks for any clarifications.




elseif ($delete) {
// delete a record
$sql = "DELETE FROM employees WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
printf("<a href=\"%s\">Return</a><br>", $_SERVER['PHP_SELF']);
}
else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM employees",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF,
$myrow["id"], $myrow["first"], $myrow["last"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>",
$PHP_SELF, $myrow["id"]);
}
}




Justin Koivisto
Guest
 
Posts: n/a
#2: Jul 17 '05

re: PSP_SELF


Buck Turgidson wrote:
[color=blue]
> I am trying to learn PHP. I am confused as to why I need
> $_SERVER['PHP_SELF'] in the first block, but just $PHP_SELF in the 2nd. I
> don't see the latter assigned anywhere in the code.
>
> Thanks for any clarifications.
>
>
>
>
> elseif ($delete) {
> // delete a record
> $sql = "DELETE FROM employees WHERE id=$id";
> $result = mysql_query($sql);
> echo "$sql Record deleted!<p>";
> printf("<a href=\"%s\">Return</a><br>", $_SERVER['PHP_SELF']);
> }
> else {
> // this part happens if we don't press submit
> if (!$id) {
> // print the list if there is not editing
> $result = mysql_query("SELECT * FROM employees",$db);
> while ($myrow = mysql_fetch_array($result)) {
> printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF,
> $myrow["id"], $myrow["first"], $myrow["last"]);
> printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>",
> $PHP_SELF, $myrow["id"]);
> }
> }[/color]

It's a bug.. both should reference $_SERVER['PHP_SELF']

$PHP_SELF is available of register_globals = On, but default install is
with register_globals = Off

--
Justin Koivisto - spam@koivi.com
http://www.koivi.com
Thomas
Guest
 
Posts: n/a
#3: Jul 17 '05

re: PSP_SELF


*Buck Turgidson wrote:
[color=blue]
> I am trying to learn PHP. I am confused as to why I need
> $_SERVER['PHP_SELF'] in the first block, but just $PHP_SELF in the 2nd.
> I
> don't see the latter assigned anywhere in the code.
>
> Thanks for any clarifications.[/color]


This has to do with the setting of register_globals:

http://no2.php.net/manual/en/security.globals.php

DO NOT use the $PHP_SELF any more, it is obsolete and will render your
code non-portable.


--
Thomas

SELECT date FROM wife WHERE bitching = '0' AND sex = '1'
Pedro Graca
Guest
 
Posts: n/a
#4: Jul 17 '05

re: PSP_SELF


Justin Koivisto wrote:[color=blue]
> Buck Turgidson wrote:[color=green]
>> I am trying to learn PHP. I am confused as to why I need
>> $_SERVER['PHP_SELF'] in the first block, but just $PHP_SELF in the 2nd.
>> I don't see the latter assigned anywhere in the code.[/color][/color]

See my comments below
[color=blue][color=green]
>> elseif ($delete) {
>> // delete a record
>> $sql = "DELETE FROM employees WHERE id=$id";
>> $result = mysql_query($sql);
>> echo "$sql Record deleted!<p>";
>> printf("<a href=\"%s\">Return</a><br>", $_SERVER['PHP_SELF']);
>> }
>> else {
>> // this part happens if we don't press submit
>> if (!$id) {
>> // print the list if there is not editing
>> $result = mysql_query("SELECT * FROM employees",$db);
>> while ($myrow = mysql_fetch_array($result)) {
>> printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF,
>> $myrow["id"], $myrow["first"], $myrow["last"]);
>> printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>",
>> $PHP_SELF, $myrow["id"]);
>> }
>> }[/color]
>
> It's a bug.. both should reference $_SERVER['PHP_SELF'][/color]

A bug .... Where is the bug?
The OP's code or the browser he's using? :-)


The first printf() will print something like

<a href="/script.php">Return</a>

whereas the second will print

<a href="?id=42">First Last</a>


And I think the OP's browser (correctly???) takes the second URL (can
that be called a URL???) as "<current_page>?id=42"




To the OP:

Buck, turn on error reporting for all notices so that you will be
notified when you use variables that do not exit (like $PHP_SELF above).

If you can't change php.ini, insert these two lines at the top of your
scripts:

error_reporting(E_ALL);
ini_set('display_errors', '1');

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
John Dunlop
Guest
 
Posts: n/a
#5: Jul 17 '05

re: PSP_SELF


Pedro Graca wrote:
[color=blue]
> the second will print
>
> <a href="?id=42">First Last</a>[/color]

<?id=42> is not a relative URI by RFC2396, and so, strictly
speaking, that isn't HTML; luckily, however, that fault was
spotted, and the BNF for relativeURI (now termed relative-
ref) has been revised. <?id=42> is valid under the current
draft-in-progress; see

<http://www.gbiv.com/protocols/uri/rev-2002/issues.html#007-empty-rel_path>
[color=blue]
> And I think the OP's browser (correctly???) takes the second
> URL (can that be called a URL???) as "<current_page>?id=42"[/color]

You'd expect that, wouldn't you?

An example from Appendix C in RFC2396 shows that with a base
URI of <http://a/b/c/d;p?q> a relative URI of <?y> resolves
to <http://a/b/c/?y>. With <?y>, you reach step 6 of
RFC2396's resolution algorithm: strip off anything after the
last slash of the base URI and append <?y> to what's left.

The draft-in-progress, on the other hand, shows an example
with the same base and relative URIs which resolves to
<http://a/b/c/d;p?y>.

<http://www.gbiv.com/protocols/uri/rev-2002/issues.html#003-relative-query>

That's the theory anyway; I don't know what browsers
actually do. Tell a lie: Lynx 2.8.3dev.17 follows RFC2396
to the letter, while Opera 7.10 follows the draft-in-
progress and RFC1808. Which browser is right? I wouldn't
call either wrong. Is it wise to use relative URIs with
empty paths? I wouldn't use them.

--
Jock
Chung Leong
Guest
 
Posts: n/a
#6: Jul 17 '05

re: PSP_SELF


Someone is thinking too much about the portable Playstation :-)


Pedro Graca
Guest
 
Posts: n/a
#7: Jul 17 '05

re: PSP_SELF


John Dunlop wrote:[color=blue]
> Pedro Graca wrote:[color=green]
>> And I think the OP's browser (correctly???) takes the second
>> URL (can that be called a URL???) as "<current_page>?id=42"[/color]
>
> You'd expect that, wouldn't you?[/color]

Yes :)
But my expectations aren't necessarily correct.


Thank you for the links and, especially, the detailed explanation.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Buck Turgidson
Guest
 
Posts: n/a
#8: Jul 17 '05

re: PSP_SELF


>[color=blue]
> That's the theory anyway; I don't know what browsers
> actually do. Tell a lie: Lynx 2.8.3dev.17 follows RFC2396
> to the letter, while Opera 7.10 follows the draft-in-
> progress and RFC1808. Which browser is right? I wouldn't
> call either wrong. Is it wise to use relative URIs with
> empty paths? I wouldn't use them.
>[/color]



I am using Opera, BTW.


Buck Turgidson
Guest
 
Posts: n/a
#9: Jul 17 '05

re: PSP_SELF


[color=blue]
> Buck, turn on error reporting for all notices so that you will be
> notified when you use variables that do not exit (like $PHP_SELF above).
>
> If you can't change php.ini, insert these two lines at the top of your
> scripts:
>
> error_reporting(E_ALL);
> ini_set('display_errors', '1');
>[/color]

This is an extract of php.ini. It appears to be set.

error_reporting = E_ALL & ~E_NOTICE
display_errors = On
display_startup_errors = Off
log_errors = Off
log_errors_max_len = 1024


Pedro Graca
Guest
 
Posts: n/a
#10: Jul 17 '05

re: PSP_SELF


Buck Turgidson wrote:[color=blue][color=green]
>> Buck, turn on error reporting for all notices so that you will be
>> notified when you use variables that do not exit (like $PHP_SELF above).[/color]
>
> This is an extract of php.ini. It appears to be set.
>
> error_reporting = E_ALL & ~E_NOTICE[/color]

This means show everything except Notices.
The use of uninitialized variables is a notice.

Change it to

error_reporting = E_ALL


and get ready to see a *LOT* ot notices about uninitialized variables.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Closed Thread