Rob
Rob

Reputation: 8101

Determining the complete URL but without the script name?

Basically I'm trying to determine the complete web-accessible URL of a certain script, but without the script name.

For example, I was thinking of something along these lines:

$fullURL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
echo $fullURL;

So if the file was http://example.com/path/to/file.php, then that's what it would display: http://example.com/path/to/file.php. However, I want it to display http://example.com/path/to/

Is this possible, and if so, how?

Upvotes: 2

Views: 679

Answers (2)

matpie
matpie

Reputation: 17522

You could use dirname().

$ScriptDir = dirname($fullURL);

Upvotes: 0

zneak
zneak

Reputation: 138171

Use the dirname function:

 $fullURL = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']);

This will exclude the last slash. You may of course append it yourself to match your preferences.

Upvotes: 5

Related Questions