Jump to content

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.

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]
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.