jakubsnm Posted September 27, 2009 Share Posted September 27, 2009 Trying to display site users IP in the footer of my site, but when I visit some secure pages I get the "non secure content on page" error. Is there some sort of IF statement I can use so my code only comes up on non secure pages? Quote Link to comment https://forums.phpfreaks.com/topic/175689-how-do-i-code-if-page-not-ssl/ Share on other sites More sharing options...
Daniel0 Posted September 27, 2009 Share Posted September 27, 2009 If you're running a standard config, HTTPS is on port 443, so you can just check if the port isn't 443. if ($_SERVER['SERVER_PORT'] == 443) { echo 'SSL'; } else { echo 'Not SSL'; } I also believe that $_SERVER['HTTPS']='on' evaluates to true if you're on HTTPS (in Apache at least). Quote Link to comment https://forums.phpfreaks.com/topic/175689-how-do-i-code-if-page-not-ssl/#findComment-925832 Share on other sites More sharing options...
MadTechie Posted September 27, 2009 Share Posted September 27, 2009 if ($_SERVER['HTTPS'] != "on") { echo 'secure'; }else { echo 'Not secure'; } EDIT: to slow! Quote Link to comment https://forums.phpfreaks.com/topic/175689-how-do-i-code-if-page-not-ssl/#findComment-925833 Share on other sites More sharing options...
Daniel0 Posted September 27, 2009 Share Posted September 27, 2009 EDIT: to slow! if ($_SERVER['HTTPS'] != "on") { echo 'SSL'; } else { echo 'Not SSL'; } You'll have to do if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') because the HTTPS index in $_SERVER is only present if you're actually on HTTPS. Otherwise you'll get that E_NOTICE about undefined indices. Also note that you've negated it, so you'll get the opposite. Quote Link to comment https://forums.phpfreaks.com/topic/175689-how-do-i-code-if-page-not-ssl/#findComment-925837 Share on other sites More sharing options...
MadTechie Posted September 27, 2009 Share Posted September 27, 2009 I hit preview, saw your code but didn't notice the note about, $_SERVER['HTTPS'] until it hit post.. what about if(!empty($_SERVER['HTTPS'])) { Quote Link to comment https://forums.phpfreaks.com/topic/175689-how-do-i-code-if-page-not-ssl/#findComment-925854 Share on other sites More sharing options...
mrMarcus Posted September 27, 2009 Share Posted September 27, 2009 what about taking care of the 'non secure content on page' error .. would also do the trick and make for less/no workarounds. Quote Link to comment https://forums.phpfreaks.com/topic/175689-how-do-i-code-if-page-not-ssl/#findComment-925858 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.