Jump to content


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

  • Please log in to reply
2 replies to this topic

#1 bilis_money

  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 07 July 2006 - 11:48 AM

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

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.

#2 Daniel0

  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 07 July 2006 - 11:54 AM


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

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/t...st.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.

#3 cmgmyr

  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 07 July 2006 - 12:14 PM

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.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users