Using page's filename

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
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Using page's filename

Post by Bennettman »

I'm making a menu page which will be included into every main page on my site. The idea is, the current page will only be text in the menu, while the rest of the pages will be links in the menu. So all I need is a command to get the current page's filename. The code goes something like this:

<?php
if (!filename("index.php")) {
print ("<a href=index.php>"); }
print ("Index</a> :: ");
?>

Where !filename would be ![command]. It's probably really simple. ;p Anyone?
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

Code: Select all

if(eregi("index.php",$REQUEST_URI)) {
  echo "Index";
} else {
  echo "&lt;a href="index.php"&gt;Index&lt;/a&gt;";
}
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Following script will print the current file's name:-

Code: Select all

&lt;?php
echo $PHP_SELF;
?&gt;
Simple...
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

$PHP_SELF could replace $REQUEST_URI, but either way I'd still use eregi to check for the match. $PHP_SELF prints /'s

You could also use $SCRIPT_NAME.. all would pretty much do the same thing.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

And if you happen to have register globals off (which is the default now), you could use:

Code: Select all

$_SERVER&#1111;'PHP_SELF']
$_SERVER&#1111;'REQUEST_URI']
$_SERVER&#1111;'SCRIPT_NAME']
(Use $HTTP_SERVER_VARS instead of $_SERVER if you have PHP 4.0.6)

Mac
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

Thanks a lot! It worked with $PHP_SELF.
Post Reply