faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

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

34 of 45 people (76%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

Why is $PHP_SELF empty from a Netscape browser but not from IE?

Aug 12th, 2000 07:48
kwaH, Nathan Wallace, David Deutsch, Sascha Schumann


Using the line:
    <A HREF="<? echo $PHP_SELF; ?>?var=something">Link Name</a>
you might get these links (as they appear in the View Source of the
browser):
    URL in IE:       http://myhost.com/phpfile.php3?var=something
    URL in Netscape: http://myhost.com/?var=something
$PHP_SELF is probably empty in both cases. Netscape doesn't conform to
RFC 2068 which says in "3.2.1 General Syntax" that URIs of the form
    ?query
are valid. IE does handle these just fine and probably combines them to
a correct URI while Netscape doesn't.
You can echo $PHP_SELF somewhere in your document where it's not part of
a link to check.
In case you have created the hyperlink from within a function or class,
you might just have forgotten to import the variable $PHP_SELF from
the global variable space.
In that case a simple 
global $PHP_SELF
should do the job.
A complete example might look like this:
function DoSomething() {
 global $PHP_SELF;
 printf ("<a href='%s?func=browse'>Browse</a>", $PHP_SELF);
 return true;
}