Jump to content

Archived

This topic is now archived and is closed to further replies.

bilis_money

"php_self" please give me your opinion? basic question?

Recommended Posts

ok, this question is pretty basic.
so i'm sure many of you can give me your thoughts.

I've been using this for a year now but still i'm not 100% so sure the purpose
of $_SERVER['PHP_SELF'];.

all i know about $_SERVER['PHP_SELF']; is to display the results on the
same page as it was.

Is this correct thought?

PLease if you have good explaination and thoughts please
explain it to me in detail.
Or if there is any fundamental purpose of this 'PHP_SELF' then
say it till i get your thought right!

Thank you very much.

Share this post


Link to post
Share on other sites
Hey,

The official description is located here description of $_SERVER['PHP_SELF'] from PHP is:

[quote]The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar  would be /test.php/foo.bar. The __FILE__  constant contains the full path and filename of the current (i.e. included) file.

If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.[/quote]

Share this post


Link to post
Share on other sites
It basically let's you use the page that you are on as a variable.

If you are on index.php you can have a for that has action=$_SERVER['PHP_SELF'] so it's like action=index.php

It's really helpful if you have a lot of links on one page that go to multiple functions index.php?action=1 index.php?action=2 you can just do $_SERVER['PHP_SELF']."?action=1" $_SERVER['PHP_SELF']."?action=2" so you don't need to type in index.php all the time. You can also change the file name, and your script will still work without recoding it. So if you changed it to index2.php, and if you were using $_SERVER['PHP_SELF'] you wouldn't have to go adding 2's all over your code. You get the point...


Hope this helped, and you can do a lot more then just that with it.

-Chris

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.