Thursday, April 30, 2009

Getting current Page Name in PHP


$_SERVER[‘PHP_SELF’] will be used for getting current page name in php.

It will be necessary for us to use this $_SERVER[‘PHP_SELF’] for action attribute of form element if you want to post the form into the same page. If you use the filename instead of this variable then we may face difficulty when we change the file name.


If the page is located in sub-folder, then this variable will return the page name along with sub-folder name also (e.g qualtypoint/index.php)

If you want to get only the filename (e.g index.php) then you should use basename() as below.
basename($_SERVER[‘PHP_SELF’])

More Articles...

No comments:

Search This Blog