tags:

views:

64

answers:

2

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?

+3  A: 

A simple Google search would have answered your question. Here's the result.

http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm

Jan Kuboschek
@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
@powerboy nope.
Col. Shrapnel
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
+1  A: 
Mihai Iorga
may be you want to learn a dirname() function
Col. Shrapnel
yea .. sorry ... i just woke up is 9 AM here ... and i forgot :)
Mihai Iorga
@Mihai Iorga - A better solution might use $_SERVER[’SCRIPT_NAME’] instead of $_SERVER['REQUEST_URI']. And what about "https://"?
powerboy
@powerboy: did you read the PHP documentation pertaining to $_SERVER? I believe php.net and its comments cover everything you're asking.
Jan Kuboschek
I've reedited the answer and added https ..good luck
Mihai Iorga