View Full Version : Obtaining A Page name from URL

10-29-2003, 11:16 AM
Im very new to PHP, so excuse my ignorance..

Say I wanted to hide bits of text/images on certain page names (i.e test.php), would that be possible with the...


If so, how could I pick out the name of a page....

Like.. if a url has : http://www.mydomain.com/test.php?catid=8
and say I wanted to find out what the php file is called?
Can I do this, i.e:

if ($page == "test.php") {
blah blah

$page could be from a 'function' routine or something?

Can this be done, as this would make coding simpler for me.

TIA and sorry if I confused you all :)

10-29-2003, 02:35 PM
If I understand, you want to know the name of the previous page users are coming from. This was given to me in other post:

$full_url = parse_url($_SERVER['HTTP_REFERER']);
$url = basename($full_url['path']);

Is that what you need?

10-29-2003, 06:44 PM
Sorry, I need the ''current' url..... I want to design an external navigation php page and ''include'' it in my main pages.

For example: If the page name is ''search.php'', the navigation page (which will be included in this page) will check the url, and then execute the relevant ''if'' statement.
If you understood that? :s

10-29-2003, 07:01 PM
change REFERER for SELF: :)

$full_url = parse_url($_SERVER['PHP_SELF']);
$url = basename($full_url['path']);

Actually with this is enough:

$url = basename($_SERVER['PHP_SELF']);

10-29-2003, 07:59 PM
Php_Self isnt that good :-/

It returns
blah/blah/blah/blah.php instead of just blah.php calling from

I made some code to return just the blah.php partand will release it soon

10-29-2003, 08:31 PM
Well, both options above are just working fine with me.