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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.