NYCPHP Meetup

NYPHP.org

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

Chris Shiflett shiflett at php.net
Wed Jul 20 19:22:55 EDT 2005


Michael Southwell wrote:
> $_SERVER['PHP_SELF'] doesn't seem to be working.

[snip]

> header("Location:$_SERVER[PHP_SELF]?action=internet&reqflag=1&join=$joinFlag");

As someone else suggested, a good first debugging step is to use echo 
instead of header(), so you see exactly what header you're sending.

In this case, there are several problems worth eliminating, most of 
which Dan pointed out:

1. No space after the colon
2. No absolute URL
3. Improper syntax for an array

When you reference an array as $_SERVER[PHP_SELF], you're telling PHP 
that the index of the element you want is the constant PHP_SELF. Once 
PHP discovers that no such constant exists, it will try to treat 
PHP_SELF as a string, in case that's what you really meant.

In a brief test, none of these mistakes made it fail to redirect, so 
there must be something else (or your browser is pickier). Perhaps 
$joinFlag is not set, and your error_reporting is set to E_ALL?

What's the behavior you're observing?

Chris

-- 
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/



More information about the talk mailing list