Re: checking for and enforcing https

From: Date: Mon, 25 Feb 2008 19:27:54 +0000
Subject: Re: checking for and enforcing https
Groups: php.general 
Request: Send a blank email to php-general+get-270111@lists.php.net to get a copy of this message
---- Stephen Johnson <maillists@thelonecoder.com> wrote: > > Or you can cheat... > > > > $url = $_SERVER['SERVER_NAME']; > > header( 'Location:https://'.$url.''); > > > > > > I think that would cause an infinite loop of redirection... > > This would be better > > <?php > > $curPort = $_SERVER['SERVER_PORT']; > $pageTo = $_SERVER['REQUEST_URI']; > > if($curPort == "80") { > // go secure > > header("location:https://www.domain.com$pageTo"); > exit; > } > ?> > > Also realize, your code ONLY works if people use the standard ports... With the way I have it check ($SERVER variables), then you eliminate that and no matter what ports the server runs on, you get the correct switching you need. Wolf

« previous php.general (#270111) next »