Problem with $PHP_SELF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Problem with $PHP_SELF

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Thats weird

maybe try echo "$PHP_SELF"; outside of the form see what happens
User avatar
Ixplodestuff8
Forum Commoner
Posts: 60
Joined: Mon Feb 09, 2004 8:17 pm
Location: Queens, New York

Post by Ixplodestuff8 »

Try $_SERVER['PHP_SELF'] or $HTTP_SERVER_VARS['PHP_SELF'] instead.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Ahh yep. $_SERVER['PHP_SELF'] did the trick. Thanks.
User avatar
harsha
Forum Contributor
Posts: 103
Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India

about $PHP_SELF

Post 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.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Re: about $PHP_SELF

Post 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).
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 :!:
Post Reply