Finding Page Path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smartweb
Forum Newbie
Posts: 7
Joined: Fri Jul 30, 2004 10:56 pm

Finding Page Path

Post by Smartweb »

How would I go about getting the file and directory (or in other words full path) of the file that's being executing into a variable?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

If you're talking about the page that's being executed right now it'd look like this.

Code: Select all

$path = $_SERVERї'PHP_SELF'] . (!empty($_SERVERї'QUERY_STRING']) ? '?' . $_SERVERї'QUERY_STRING'] : '');
I just recently asked a question similar to this and that code to find the full path, including the page and query string was shown to me by Feyd. :). He knows alot.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Or $_SERVER['SCRIPT_FILENAME'] to get the path to the script relative to the file system.
Smartweb
Forum Newbie
Posts: 7
Joined: Fri Jul 30, 2004 10:56 pm

Post by Smartweb »

Yeah, thanks, that's exactly what I wanted. :)
Post Reply