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?
Basename and Server Request URI
Moderator: General Moderators
- 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
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.
Re: Basename and Server Request URI
They just return /page/index.php or index.php when used with basename().
- 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
Sorry:
Also, look at parse_url().
Code: Select all
echo basename(dirname($_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.
Re: Basename and Server Request URI
Perfect! Thanks buddy 