PHP_SELF error

software development

#1

I’m having some weird deal with PHP_SELF;

I am getting “http:/blah/blah” out of this instead of “http://domain.com/blah/blah”,

The ‘//domain.com’ is not coming.

BUT… if I break it, make it say " $_SERVER[“PHP_SELF1”] " … add a 1, add whatever in there. break it.

It … works perfectly. I get a properly build link.

echo " LinkEntries[" . $LinkEntriesCount . “] = “http:” . $_SERVER[“PHP_SELF”] . “?year=$year&month=$month&day=$day&resource=$resource&InstructorResource=InstructorTZ$makemodel”;”;
$LinkEntriesCount = $LinkEntriesCount + 1;

I found a ‘fix’ in some of the WordPress forums:

// Fix for Dreamhost and other PHP as CGI hosts
if ( strstr( $_SERVER[‘SCRIPT_NAME’], ‘php.cgi’ ) )
unset($_SERVER[‘PATH_INFO’]);

// Fix empty PHP_SELF
$PHP_SELF = $_SERVER[‘PHP_SELF’];
if ( empty($PHP_SELF) )
$_SERVER[‘PHP_SELF’] = $PHP_SELF = preg_replace("/(?.*)?$/",’’,$_SERVER[“REQUEST_URI”]);

… if I put that in, it still does not work.

Really silly stuff…


#2

You have failed to read the PHP documentation. Please refer to PHP: Predefined Variables The relative sections are copied below.

'PHP_SELF’
The filename of the currently executing script, relative to the document root. For instance, $_SERVER[‘PHP_SELF’] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The FILE constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.

'SERVER_NAME’
The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

'REQUEST_URI’
The URI which was given in order to access this page; for instance, ‘/index.html’.

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#3

Well… I wouldn’t exactly say I failed to read it. I’ve been all over that section trying to understand this- I’ve taken a script that works just fine on many other hosts and deployed it here only to have it not work completely due to SCRIPT_NAME wanting to be SCRIPT_URL which fixed that problem, but this- gives me back either null variables or the name of the script. My point is, breaking it by echoing an invalid variable makes it work just fine, leaving it alone and it leaves out the domain name, but I get the rest of the URL just fine.

Now, reading the PHP_SELF, I interpret that as the script name itself, not the entire URL to the script name, so I don’t quite understand how this works.

But something with PHP as CGI is causing the intended output to, well, not come out as intended.

My choices are find syntax that works, or ditch the whole thing and use a global variable in the config. table that has the domain the script is being executed from, instead.


#4

you can actually start your links with the ? — I do this all the time. For example, if you’re on http://example.com/dir/page.php and want to get to http://example.com/dir/page.php?sort=name you can link to any one of these to get there:

?sort=name
page.php?sort=name
/dir/page.php?sort=name (note: this is $_SERVER[‘PHP_SELF’] . ‘?sort=name’ in php)
http://example.com/dir/page.php?sort=name (note: this is ‘http://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘PHP_SELF’] . ‘?sort=name’ in php)

track7 - my dream-hosted site