why $PHP_SELF is not working in localhost

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
pankajdeoria
Forum Newbie
Posts: 15
Joined: Thu Mar 12, 2009 10:58 am
Location: Bangalore,India

why $PHP_SELF is not working in localhost

Post by pankajdeoria »

What is $PHP_SELF and why it is not working in Localhost? I am using wampserver software.
Thank You
Theory?
Forum Contributor
Posts: 138
Joined: Wed Apr 11, 2007 10:43 am

Re: why $PHP_SELF is not working in localhost

Post by Theory? »

$PHP_SELF is a preset constant in the PHP compiler that basically holds the value of the document that is calling the variable. So if you use $PHP_SELF in login.php assume the value is being replaced by the compiler with login.php. As to why it's not working, are you sure you're typing it properly. It's not a stand-alone variable, it's a value that is stored in an array of $_SERVER[] values. The proper usage is something like:

Code: Select all

<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>" >
 
//...your form here
 
</form>
 
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: why $PHP_SELF is not working in localhost

Post by Jenk »

Code: Select all

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
 
//...your form here
 
</form>
 
Small correction, added echo. :)

This is not an "Advanced Discussion"
Post Reply