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
akphidelt
Forum Newbie
Posts: 6 Joined: Wed Feb 13, 2008 2:09 pm
Post
by akphidelt » Mon Feb 25, 2008 11:52 am
Hey there, I'm having a problem getting $_SERVER['PHP_SELF'] to work properly. Im trying to attach it to a form... so I have it like this
Code: Select all
$server = $_SERVER['PHP_SELF'];
<FORMS METHOD="POST" ACTION="$server">
But when I click on the submit button for the form it gives me an error and the URL looks like this
http://localhost/.'/currentpage.php
I can't for the life of me find a solution on the internet and was wondering if you guys had a clue on what was going on!
yacahuma
Forum Regular
Posts: 870 Joined: Sun Jul 01, 2007 7:11 am
Post
by yacahuma » Mon Feb 25, 2008 12:26 pm
you can also use action="#" I am not sure if there is anything bad about doing this.
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Mon Feb 25, 2008 12:41 pm
echo the value of $server to see what it contains. You will probably see immediately what needs to be done to form a valid URL.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Mon Feb 25, 2008 12:43 pm
Well first of all you can't just output html directly in php. You have to "exit" out of php first...
Code: Select all
<?php
$server = $_SERVER['PHP_SELF'];
?>
<FORMS METHOD="POST" ACTION="<?php echo $server; ?>">
Second,
don't use PHP_SELF .
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Mon Feb 25, 2008 2:45 pm
Try something like this:
Code: Select all
<?php
$action = basename(__FILE__);
?>
<FORMS METHOD="POST" ACTION="<?php echo $action; ?>">
PHP_SELF is a very insecure way of capturing the current page name. Ask Ninja.
He wrote an article on it .