Ninjakreborn Posted June 5, 2007 Share Posted June 5, 2007 In php is there a way to force if they are at https://www.domainname.com and if not then redirect them to the https version?? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/54324-solved-ssl-forcing/ Share on other sites More sharing options...
Caesar Posted June 5, 2007 Share Posted June 5, 2007 <?php if($_SERVER['SERVER_PORT'] == '80') { header("Location: https://mydomain.com"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54324-solved-ssl-forcing/#findComment-268641 Share on other sites More sharing options...
Ninjakreborn Posted June 5, 2007 Author Share Posted June 5, 2007 ah perfect, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/54324-solved-ssl-forcing/#findComment-268642 Share on other sites More sharing options...
Ninjakreborn Posted June 5, 2007 Author Share Posted June 5, 2007 Not working it sits there 5 minutes and comes up with page notfound. I need when someone goes to the page it needs to take them to https so it's on a secure connection, anymore advice? Quote Link to comment https://forums.phpfreaks.com/topic/54324-solved-ssl-forcing/#findComment-268646 Share on other sites More sharing options...
Ninjakreborn Posted June 5, 2007 Author Share Posted June 5, 2007 nevermind, got it thanks. Quote Link to comment https://forums.phpfreaks.com/topic/54324-solved-ssl-forcing/#findComment-268648 Share on other sites More sharing options...
Caesar Posted June 5, 2007 Share Posted June 5, 2007 Not working it sits there 5 minutes and comes up with page notfound. I need when someone goes to the page it needs to take them to https so it's on a secure connection, anymore advice? Hmmm....should work.. I'll test on my Linux box to be sure. Quote Link to comment https://forums.phpfreaks.com/topic/54324-solved-ssl-forcing/#findComment-268649 Share on other sites More sharing options...
Caesar Posted June 5, 2007 Share Posted June 5, 2007 nevermind, got it thanks. Cool. :-) What was it? Quote Link to comment https://forums.phpfreaks.com/topic/54324-solved-ssl-forcing/#findComment-268653 Share on other sites More sharing options...
Ninjakreborn Posted June 7, 2007 Author Share Posted June 7, 2007 <?php if($HTTP_SERVER_VARS["HTTPS"] != "on") { $newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; header("location: $newurl"); } ?> Just put this code at the top of every page that you need to force ssl. I also attempted to turn it into a function but haven't tested/debugged it yet. <?php // function forces https connection (simply put the function at the // top of whatever pages need to have forced SSL (assuming SSL is active on the site). function forcesecure() { if($HTTP_SERVER_VARS["HTTPS"] != "on") { $newurl = "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; header("location: $newurl"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54324-solved-ssl-forcing/#findComment-269956 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.