$_SERVER[]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
truepal20032001
Forum Commoner
Posts: 27
Joined: Mon Jun 25, 2007 8:28 pm

$_SERVER[]

Post by truepal20032001 »

Is there a $_SERVER[] function that returns a string of the directory... , not necessarily "PHP_SELF" but is there another one that will give you with the full URL like ------
"http://website.com/folder1/folder/
excluding the file itself....
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: $_SERVER[]

Post by omniuni »

Not so far as I know. I spent a while looking for this myself, and gave up. You'll have to either parse the string yourself, or figure some other solution.

If you find this, though, I would love to know. It would simplify things.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: $_SERVER[]

Post by requinix »

In $_SERVER the formula is

Code: Select all

"http://" + SERVER_NAME + ":" + SERVER_PORT + dirname(SCRIPT_NAME)
The :port can be omitted if you're on port 80. If the server is on Windows then dirname will return give you a string with \s that need to be converted to /s.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: $_SERVER[]

Post by omniuni »

would you mind elaborating on that just a bit?
truepal20032001
Forum Commoner
Posts: 27
Joined: Mon Jun 25, 2007 8:28 pm

Re: $_SERVER[]

Post by truepal20032001 »

tasairis wrote:In $_SERVER the formula is

Code: Select all

"http://" + SERVER_NAME + ":" + SERVER_PORT + dirname(SCRIPT_NAME)
The :port can be omitted if you're on port 80. If the server is on Windows then dirname will return give you a string with \s that need to be converted to /s.
thankyou!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: $_SERVER[]

Post by califdon »

It's all there: http://us.php.net/reserved.variables.server

Just enter $_SERVER into Google.
Post Reply