Re: checking for and enforcing https
| From: | Jim Lucas | Date: | Tue, 26 Feb 2008 16:12:45 +0000 |
| Subject: | Re: checking for and enforcing https | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-270181@lists.php.net to get a copy of this message | ||
Robert Cummings wrote:
On Tue, 2008-02-26 at 11:00 -0500, Dan Joseph wrote:And it doesn't say "off". It either exists or doesn't. if ( isset($_SERVER['HTTPS']) ) { // Is using SSL } else { // Is NOT using SSL } -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William ShakespeareOn Tue, Feb 26, 2008 at 10:56 AM, tedd <tedd.sperling@gmail.com> wrote:Surely you mean $_SERVER['HTTPS'] and not $_ENV['HTTPS']. Cheers, Rob.So, let's say I wanted script "secure.php" to be forced to use https -- do I use something like what Dan provided, namely? <?Yep. Use that or: if ($_ENV["HTTPS"] == "off"). Daniel's code is port specific, this one checks for HTTPS being on or off.if($_SERVER['SERVER_PORT'] != '443') { $url = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] :$_SERVER['SERVER_NAME'];header("Location:https://".$url.$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']);exit; }?> I know I could test the code for myself, but this is quicker.