For example, the url http://www.domain.com/folder/script.php sends a request to /var/www/domain/folder/script.php. In script.php, I want to echo http://www.domain.com/folder/ (not /var/www/domain/folder/, not http://www.domain.com/folder/script.php). What is the simplest way to do this?
views:
64answers:
2
+3
A:
A simple Google search would have answered your question. Here's the result.
Jan Kuboschek
2010-05-25 05:35:57
@Jan - $_SERVER[’PHP_SELF’], $_SERVER['REQUEST_URI'] and $_SERVER[’SCRIPT_NAME’] return path with script file name instead of the path alone. I want to know if there is a variable set to the path alone.
powerboy
2010-05-25 05:45:05
@powerboy nope.
Col. Shrapnel
2010-05-25 05:57:18
See solution by Mihai Iorga below. PHP doesn't come with that function out of the box, but with about half a minute of time, you can get the desired functionality. That takes less time than posting on SO.
Jan Kuboschek
2010-05-25 05:58:46
@Mihai Iorga - A better solution might use $_SERVER[’SCRIPT_NAME’] instead of $_SERVER['REQUEST_URI']. And what about "https://"?
powerboy
2010-05-25 06:04:20
@powerboy: did you read the PHP documentation pertaining to $_SERVER? I believe php.net and its comments cover everything you're asking.
Jan Kuboschek
2010-05-25 06:08:15