Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-14-2003, 04:34 PM   #1
Senior Member
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
php: function to retrieve filename?


What I need is a function that simply returns its own filename. ie: if the function is called from foo.php it should return foo.php or /long/path/to/foo.php or really, just anything that contains foo.php in it, that I could customize to do what I need.

I tried $PHP_SELF but it did not work correctly, In fact it appeared to do nothing.

$filename = $PHP_SELF

Perhaps I need to use this another way?
Perhaps there is an enviromental variable or array that contains the filename?
Any help/ideas appreciated.
Old 10-14-2003, 04:48 PM   #2
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
I had the same problem, except the other way around. To find the correct variable, 'phpinfo();' will give all the variable's you can use.
Old 10-14-2003, 05:09 PM   #3
Senior Member
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
Looks to me like you want to use $_SERVER['PHP_SELF'] which is the name of the php file itself. Note that $PHP_SELF would work if register_globals is on in your php.ini, but this is a bad idea. See for furter predefined variables.


Old 10-15-2003, 07:26 AM   #4
Senior Member
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760

Original Poster
Blog Entries: 4

Rep: Reputation: 78
$_SERVER['PHP_SELF'] worked perfect,
Thanks JHarris...

I knew it had to be something simple. I haven't programmed any php since they changed the default to "register_globals = off" and I just can't seem to get my head around it.


I was reading the link provided above and found an even more succinct solution:
From php manual:
"The absolute pathname of the currently executing script. "

I did need the absolute path so this saves me from:
or even worse:

$foo = "/path/to/my/shizzle" . $_SERVER['PHP_SELF']
Thanks again

Last edited by bulliver; 10-15-2003 at 06:04 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fatal Error - Call to undefined function : pg_pconnect() in filename.php on line xx mwpeng Linux - Newbie 1 02-26-2005 08:57 AM
php HTTP_RAW_POST_DATA na value in function dinges Linux - Software 1 12-26-2004 04:11 AM
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 12:08 PM
PHP - mail function saravanan1979 Programming 2 08-06-2003 01:46 AM
PHP Script to retrieve queries from log file saravanan1979 Programming 1 03-17-2002 08:13 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:06 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration