Page 1 of 1

Basename and Server Request URI

Posted: Mon May 09, 2011 12:04 pm
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?

Re: Basename and Server Request URI

Posted: Mon May 09, 2011 12:29 pm
by AbraCadaver
Try $_SERVER['SCRIPT_NAME'] or $_SERVER['PHP_SELF']

Re: Basename and Server Request URI

Posted: Mon May 09, 2011 12:38 pm
by djwk
They just return /page/index.php or index.php when used with basename().

Re: Basename and Server Request URI

Posted: Mon May 09, 2011 12:42 pm
by AbraCadaver
Sorry:

Code: Select all

echo basename(dirname($_SERVER['PHP_SELF']));
Also, look at parse_url().

Re: Basename and Server Request URI

Posted: Mon May 09, 2011 12:49 pm
by djwk
Perfect! Thanks buddy :)