Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for https

Status
Not open for further replies.
That kind of thing really is better handled at the web server rather than in code.

Since you haven't specified which of the myriad possible PHP run environments is yours, I recommend that you create a phpinfo script:

<?php
phpinfo();
?>

and point your browser to it, once by HTTPS, once by HTTP.

Compare the contents of the $_SERVER superglobal array. There may be differences in elements of that array.

I know on my system (LAMP w/ mod_ssl), if I connect by HTTPS there is an element in $_SERVER with the index 'SSL_PROTOCOL'. That element is not present when I connect by HTTP.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Try this function:
Code:
  function requireSSL() {
    if (!array_key_exists(&quot;HTTPS&quot;,$_SERVER) ||
        $_SERVER[&quot;HTTPS&quot;] != &quot;on&quot;) {
      header(&quot;Location: [URL unfurl="true"]https://&quot;[/URL] .
             $_SERVER[&quot;SERVER_NAME&quot;] .
             $_SERVER[&quot;PHP_SELF&quot;]);
    }
  }
If you call it at the beginning of your page, it will automatically redirect the user to the https:// URL if they are using it from the http:// URL.

(Note the forum is changing the case of the http in HTTPS for some reason to lower. It should be all upper.)
 
how would I call the function?

<body onLoad=requireSSL();>
???

thanks for the info btw
 
Ignore me, it's 2:30am and I wasnt thinking.

I got it working thanks!
 
sleipnir214
The TGML folks have a bug in the language.
Outside of the tags you can easily type HTTP and it will stick. Inside tags however HTTP is always translated to its lowercase equivalent - they probably assumed that it is the beginning of a URL.
The following is UPPERCASE inside the [i g n o r e] tag:
[ignore]I really typed HTTP in UPPERCASE[/ignore]
Same for [c o d e]:
Code:
 HTTP_POST_VARS all in CAPS

TGML chops down the upercase HTTP. Maybe someone will take care of that eventually...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top