NYCPHP Meetup

NYPHP.org

[nycphp-talk] $_SERVER['PHP_SELF'} not working?

Dan Cech dcech at phpwerx.net
Wed Jul 20 10:21:28 EDT 2005


Michael Southwell wrote:
> I have run into an odd (odd to me, at least) problem where 
> $_SERVER['PHP_SELF'] doesn't seem to be working.
> 
> The code is this:
> ===========
>    // required entries missing
>    if ( $reqEntries < 6 ) {
>      header( 
> "Location:$_SERVER[PHP_SELF]?action=internet&reqflag=1&join=$joinFlag");
> 
> // debug
> exit( "reqentries is $reqEntries so exiting" );
> 
>    }
> ===========
> This is working perfectly on my localhost, PHP 4.3.9, Apache 1.3.24.  It is 
> not working on my test site,
> PHP 4.3.11, Apache 1.3.33.  The debug exit shows that the if clause is 
> true, and it's the header that's not
> working.  phpinfo seems to show nothing weird or unexpected about the value 
> of _SERVER['PHP_SELF']
> on the test site.
> 
> Anybody have any ideas about what might be going on here?  Thanks in advance.

I'm not sure, but I can think of 2 things that might be the cause:

1. No space between Location: and the URL
2. Non-absolute URL

You could try:

header('Location: http://'. $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] 
.'?action=internet&reqflag=1&join='. $joinFlag);

Also, you could try echoing the location string directly to see what is 
being sent.

Dan

> 
> Michael Southwell, Vice President for Education
> New York PHP
> http://nyphp.org/twoday - In-depth PHP Training Courses



More information about the talk mailing list