Link to home
Start Free TrialLog in
Avatar of formadmirer
formadmirerFlag for United States of America

asked on

Examine Part of URL

Hello all. I'm trying to figure out how to parse part of a url to determine the associated directory. For example, the URL is:

http://mywebsite.com/admin/something.php
-or-
http://mywebsite.com/user/something.php

I need to determine if the URL contains 'admin' or 'user'.

PHP 5.4

Thanks!
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

This is probably a good place to start

http://www.php.net/parse_url
Have you looked into dirname() for php4 and php5?

string dirname ( string $path )
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can find this information in $_SERVER["HTTP_HOST"] and $_SERVER["REQUEST_URI"].  The HTTP_HOST will be mywebsite.com and the REQUEST_URI will be /admin/something.php

But that said, whenever I see a question like this, I wonder about the back-story.  Why does your PHP script need to know this information?  There is almost always some reason that can build a security flaw into your design.
Avatar of formadmirer

ASKER

This worked perfect for my needs - thank you!