Page 1 of 1

Problem with $PHP_SELF

Posted: Wed Feb 18, 2004 10:35 pm
by Steveo31
Hey all-

I used a snippet from "Programming PHP", but it's not workin... could it be because I am using a local server (Apache)? Or am I missin somethin...

Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?

if(!empty($_POST['name'])){
	echo "Greetings, {$_POST['name']}, welcome.";
}

?>

<form action="<? $PHP_SELF ?>" method="post">
	<input type="text" name="name">
	<input type="submit">
</form>
</body>
</html>
Says that the $PHP_SELF is an undefined variable... more like:

Code: Select all

Forbidden
You don't have permission to access /&lt;br /&gt;&lt;b&gt;Notice&lt;/b&gt;: Undefined variable: PHP_SELF in &lt;b&gt;c:\program files\easyphp1-7\www\formtester.php&lt;/b&gt; on line &lt;b&gt;16&lt;/b&gt;&lt;br /&gt; on this server.
-S

Posted: Wed Feb 18, 2004 10:47 pm
by John Cartwright
Thats weird

maybe try echo "$PHP_SELF"; outside of the form see what happens

Posted: Wed Feb 18, 2004 10:59 pm
by Ixplodestuff8
Try $_SERVER['PHP_SELF'] or $HTTP_SERVER_VARS['PHP_SELF'] instead.

Posted: Wed Feb 18, 2004 11:36 pm
by Steveo31
Ahh yep. $_SERVER['PHP_SELF'] did the trick. Thanks.

about $PHP_SELF

Posted: Thu Feb 19, 2004 4:04 am
by harsha
$PHP_SELF behaves strangely on some system typing localhost won't work and 127.0.0.1 works and in this case (Mostly) $PHP_SELF won't work and thatz what i have observered.

but using $_SERVER['PHP_SELF'] is better.

Re: about $PHP_SELF

Posted: Thu Feb 19, 2004 7:24 am
by d3ad1ysp0rk
harsha wrote:$PHP_SELF behaves strangely on some system typing localhost won't work and 127.0.0.1 works and in this case (Mostly) $PHP_SELF won't work and thatz what i have observered.

but using $_SERVER['PHP_SELF'] is better.

uh.. i believe it's because $php_self is a registered global var, and his setting is probably off (which is a good idea).

Posted: Thu Feb 19, 2004 11:51 am
by ol4pr0

Code: Select all

$php_self
Will work if you set Global=On ;-)
LiLpunkSkateR wrote: uh.. i believe it's because $php_self is a registered global var, and his setting is probably off (which is a good idea).
Yep :!: