$_SERVER(PHP_SELF) - question

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
knds
Forum Newbie
Posts: 1
Joined: Mon Aug 20, 2007 12:42 am

$_SERVER(PHP_SELF) - question

Post by knds »

a newbie question, i've searched and tried other php functions but can't resolve this
i have 3 files, index.php, list.php and form.php
my site is basically a comments page, my index.php shows list.php(previous comments) and form.php(form to input comment)

first file is index.php
script inside calls list.php and form.php via include

inside list.php i used the script $_SERVER(PHP_SELF)


when i load the index.php
the value of $_SERVER(PHP_SELF) -- i used an echo $_SERVER(PHP_SELF) in line 2 of list.php
is "mysite.com/index.php"

but when i clicked on form.php, i have a submit button here to input comment.
and the value of $_SERVER(PHP_SELF) changed "mysite.com/list.php"
*** when i clicked on the submit button the url is still "mysite.com/index.php"

when I refresh the page the value changes again to "mysite.com/index.php"


is there a way for me to get "mysite.com/index.php" by not hard coding the value?


Thanks in Advance
:roll:
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

I take it you mean the action within your form? Hardcoding it to go to another page, or leave it blank are the best ways, PHP_SELF has security vunerabilities, and its probably not a good idea to use it, especially if its doing crazy things like you've explained.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Show your script code
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

Post by Jaxolotl »

Just a comment, I think it would be more correct to write $_SERVER['PHP_SELF'] instead of $_SERVER(PHP_SELF) because $_SERVER is an predefined php array an you are retriving value of the key PHP_SELF.
If you use the () it seem you're defining the array $_SERVER as $_SERVER = array( '0' => 'PHP_SELF'); and I'd be surprised if it works. Do you have error reporting turned on or off?

PHP manual -> $_SERVER
http://ar2.php.net/manual/en/reserved.v ... les.server
Post Reply