Page 1 of 1

$_SERVER(PHP_SELF) - question

Posted: Mon Aug 20, 2007 1:01 am
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:

Posted: Mon Aug 20, 2007 1:11 am
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.

Posted: Mon Aug 20, 2007 8:57 am
by aceconcepts
Show your script code

Posted: Mon Aug 20, 2007 9:58 am
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