$_SERVER equivalent for http://, SSL, and WWW?

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
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

$_SERVER equivalent for http://, SSL, and WWW?

Post by JAB Creations »

What is the $_SERVER or equivalent for http://, with or without SSL, and WWW? I'm looking all over the predefined variables on php.net without any luck. :|
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by Eran »

Code: Select all

$_SERVER['SERVER_PROTOCOL'];
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by JAB Creations »

Gah...I guess not. :| Thanks though. More procedural programming to work towards my CMS goal in the other thread. :lol:
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by Eran »

?

what exactly you are looking for, I thought it was the protocol of the request?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by requinix »

I doesn't make sense for a webserver to do anything over a protocol other than HTTP. It's like... I don't even know, but it's like something that's unusual.

$_SERVER["HTTPS"] is defined for a secure connection. If defined use https otherwise use http. "www"? That's the server name. Look in $_SERVER["HTTP_HOST"] for what the browser requested, ["SERVER_NAME"] for what "server" handled the request.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by Eran »

A webserver might not, but PHP might. For example a cron, or a request from a mail stream. Not sure what JAB had in mind exactly...
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by JAB Creations »

I don't want to go off-topic but in order to test this I was trying to see what would happen if I requested the same test page via SSL (and got a 403 error)...12 hours towards the end of my day (and smack in the middle of the thread :roll:). Any way I can do a very simple if condition (once I personally verify the result for SSL, 1.0, and 1.1) to construct that part of the URL.

No, I'm just trying to make sure when I construct the URL that it's always 100% the exact same as the requested URL. In example I use an Apache script that redirects non-WWW requests to the same URL with WWW, if for some reason I forgot this I'd want PHP to dynamically handle it with or without the WWW versus breaking altogether if possible?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by Eran »

What about $_SERVER['REQUEST_URI']? returns the requested address
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by JAB Creations »

What I'm trying to do...well I'm trying to recreate the URL to then explode it against the $cms->get('base') (element) href value (from the other thread). I'll take $piece[1] and determine the path of the current file to determine what row in the cms_pages MySQL table contains all the CMS information. So in simple terms, I'm trying to determine the page's relevant string to use in the MySQL query that will return all the CMS information stored in database (meta, title, etc) as was the topic in this thread.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: $_SERVER equivalent for http://, SSL, and WWW?

Post by JAB Creations »

pytrin wrote:What about $_SERVER['REQUEST_URI']? returns the requested address
It doesn't return any of the following...
http://
https://
http://www.
https://www.

With $_SERVER['REQUEST_URI'] alone I could still do what I want, I'd just have to be on my toes and make sure that each domain always redirects any non-WWW URL to a WWW URL.
Post Reply