How can i get the current pagename?

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
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

How can i get the current pagename?

Post by fastfingertips »

I'm interested to store the current page name, how can i do that?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$_SERVER['PHP_SELF'] ..

or basename($_SERVER{'PHP_SELF']) for JUST the page name (and not it's path).

There's also __FILE__ :o
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post by Pozor »

hello,

$_SERVER['PHP_SELF'] shows the file name with the relative path from the host

__FILE__ shows the translated path of the current file


example file on the root folder (www folder or html folder, depends on the provider):

__FILE__ : /home/develop/public_html/test_selfname.php
$_SERVER[PHP_SELF]: /test_selfname.php


to get only the filename you can use this:

Code: Select all

<?php
$result = explode('/',__FILE__);
or
$result = explode('/',$_SERVER['PHP_SELF']);
?>

greez Pozor
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To get only the filename from a path, you don't need to explode the string, just use [php_man]basename[/php_man]() like markl999 suggested.

Mac
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post by Pozor »

hello,

sorry i was to fast... i didn't read it very properly :oops:

I never used this... i'm still learning thanks

greez pozor

edit:

PS: it doesn't matter if you have a string like this: blabla/file.php?var=gugus ?
Post Reply