Jump to content

How do I code "IF page not SSL"


jakubsnm

Recommended Posts

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).

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.