Basename and Server Request URI

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
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Basename and Server Request URI

Post by djwk »

Hi,

I am using the following code:
echo basename($_SERVER['REQUEST_URI']);

If I navigate to http://localhost/orders/ the result I get is "orders", perfect.
If I navigate to http://localhost/findorder/ the result I get is "findorder", again perfect.
However if I navigate to http://localhost/vieworder/?id=2564 the result I get is "?id=2564".

The result I am looking for is "vieworder" but I cannot seem to find any code that will do this and still return the same for the first two examples. Does any one know of a way I can acheive this?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Basename and Server Request URI

Post by AbraCadaver »

Try $_SERVER['SCRIPT_NAME'] or $_SERVER['PHP_SELF']
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Re: Basename and Server Request URI

Post by djwk »

They just return /page/index.php or index.php when used with basename().
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Basename and Server Request URI

Post by AbraCadaver »

Sorry:

Code: Select all

echo basename(dirname($_SERVER['PHP_SELF']));
Also, look at parse_url().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
djwk
Forum Commoner
Posts: 56
Joined: Tue Mar 07, 2006 2:14 pm

Re: Basename and Server Request URI

Post by djwk »

Perfect! Thanks buddy :)
Post Reply