faqts : Computers : Programming : Languages : PHP : Installation and Setup : Operating Systems : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

77 of 94 people (82%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

Why does PHP_SELF contain php.exe?
Why do my URL's contain php.exe?

Nov 30th, 2000 02:30
geoffrey bazira, Nathan Wallace, Richard Lynch, Robin Gibson


On Windows, when you give any php3 url in the browser, say:

    http://localhost/hello.php3

and the php3 script calls itself in the script from a form submit, i.e:

    <form action=<?php echo $PHP_SELF ?>

then when the script runs the second time, the url changes to:

    http://localhost/php3/php.exe/hello.php3

It seems goofy, but that's how Apache actually does the Action stuff: 
It maps it into a big long URL that has php.exe in it and the script you
want.  So your action definition in the httpd.conf probably looks like
this:

    Action application/x-httpd-php3 "/php3/php.exe"

You can just use ACTION=hello.php3 instead of $PHP_SELF if you prefer.

There is a simple fix.  Just add this line to the beginning of any page
using the $PHP_SELF global:

    $PHP_SELF = str_replace($SCRIPT_NAME, "", $PHP_SELF);

$SCRIPT_NAME contains (e.g..)  "/php3/php.exe" - the path to the PHP
executable. The fix yanks that out of $PHP_SELF.

If you wish to use $SCRIPT_NAME, a simple fix would also be:
$SCRIPT_NAME = substr($PHP_SELF, strlen($SCRIPT_NAME));