$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
User avatar
richie256
Forum Commoner
Posts: 37
Joined: Mon Oct 13, 2003 8:00 pm
Location: Montréal/Canada

$PHP_SELF

Post by richie256 »

I don't know why, but I am getting this error:

Code: Select all

Forbidden
You don't have permission to access /<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>C:/Program Files/Apache Group/Apache2/htdocs/clients.php</b> on line <b>203</b><br /> on this server.
here on line 203:

Code: Select all

<?php
<form method="post" action="<?php echo $PHP_SELF; ?>?mode=add">
?>
I really don't know why I can't use $PHP_SELF
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

<?php echo $_SERVER['PHP_SELF']; ?>

See http://php.net/variables.predefined for more info
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

$_SERVER['PHP_SELF']

// or EDIT:

action={$_SERVER['PHP_SELF']} method="GET"       ect...
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

I had this problem.

Code: Select all

<form method="get" action="<?php $_SERVER['PHP_SELF'] ?>">
You cant have it be a POST form with GET variables appended to it. :)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You cant have it be a POST form with GET variables appended to it.
Sure you can :o
Example:

Code: Select all

<?php
if(!empty($_GET)){
    var_dump($_GET);
}
if(!empty($_POST)){
    var_dump($_POST);
}
?>
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?id=45">
<input type="text" name="uname">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Really... wow. My bad. Didn't know that :)
Post Reply