$PHP_SELF not working correctly...

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
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

$PHP_SELF not working correctly...

Post by Hibba »

Below I have a basic php file that displays a form if 'submit' is not set. I have the html file by itself and bring it in using file_get_contents, but the $PHP_SELF within that HTML file does not seem to work. Why?

Code: Select all

<?
extract($_Post);

if (!isset($submit)) {	//if the form has NOT been submitted, show the following HTML

echo file_get_contents('donate_form.html');

} else {	//if it HAS been submitted, give them text

	//email variables and POST again

}

?>

//donate_form.html (below)

<html>

     html...
		<form id="FormName" action="<?=$PHP_SELF?>" method="POST" name="FormName">

      html...
		</form>
	</html>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

nowadays that is

Code: Select all

$_SERVER['PHP_SELF']
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post by Hibba »

Hmm, do you mean action="<?=$_SERVER['PHP_SELF']?> ??

Cause this does not seem to work either.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

sometimes peoples php installation doesnt define the php_self variable for some reason.

i have no clue why.
only thing i can think of is if track_vars is off

ive seen a few people mention this.

make sure short tags is turned on as well
try using <?php echo instead of <?=
Last edited by rehfeld on Wed Dec 15, 2004 9:13 pm, edited 1 time in total.
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post by Hibba »

This is just installed on my powerbook with the local Apache server...

Is there a way I can check this?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

yes do

phpinfo();
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post by Hibba »

It says this:
_SERVER["PHP_SELF"]
/simple forms/phpinfo.php (which was the file that I used to access it)

This worked in another php file I used. It seems like having it with file_get_contents messes it up or something...
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

file_get_contents reads the file into a string, it does not parse it

use include()
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post by Hibba »

But if I use include(), then I will need to escape all quotes. Correct? Also wouldn't I need to assign the HTML to a variable and then return(variable)??

thanks so much.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

no, the webserver will only parse as php blocks between <? and ?> or <?php and ?> if short open tags is off.
so you don't need to escape any quotes that are not inside those tags
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

Post by Hibba »

Right, but the include is between PHP blocks in the main file. When I submit now, it returns me back to the page, also has a "1" at the bottom of the form.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

<?
#good bye extract 
if (!isset($_POST['submit'])) { 
include('donate_form.html');
} else {    //if it HAS been submitted, give them text
    //email variables and POST again
}
?>
//donate_form.html (below)
<html>
        <form id="FormName" action="<?echo $_SERVER['PHP_SELF'];?>" method="POST" name="FormName">
        </form>
    </html>
Have a nice Day :)
Post Reply