Re: checking for and enforcing https

From: Date: Tue, 26 Feb 2008 16:00:57 +0000
Subject: Re: checking for and enforcing https
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-270177@lists.php.net to get a copy of this message
On Tue, Feb 26, 2008 at 10:56 AM, tedd <tedd.sperling@gmail.com> wrote: > > So, let's say I wanted script "secure.php" to be forced to use https > -- do I use something like what Dan provided, namely? > > <? > 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. > > Yep. Use that or: if ($_ENV["HTTPS"] == "off"). Daniel's code is port specific, this one checks for HTTPS being on or off. -- -Dan Joseph "Build a man a fire, and he will be warm for the rest of the day. Light a man on fire, and will be warm for the rest of his life."

« previous php.general (#270177) next »