Skip to content

Instantly share code, notes, and snippets.

@jubalm
Created August 24, 2012 08:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jubalm/3447495 to your computer and use it in GitHub Desktop.
Save jubalm/3447495 to your computer and use it in GitHub Desktop.
PHP - check if SSL is enabled
<?php
function is_ssl() {
if ( isset($_SERVER['HTTPS']) ) {
if ( 'on' == strtolower($_SERVER['HTTPS']) )
return true;
if ( '1' == $_SERVER['HTTPS'] )
return true;
} elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
return true;
}
return false;
}
?>
@Riyazkhan1989
Copy link

Thanks Jubalm.

@Riyazkhan1989
Copy link

Why you check 443. Why we check this case?

@jubalm
Copy link
Author

jubalm commented Jan 20, 2020

Why you check 443. Why we check this case?

HTTPS connections utilize the TCP port 443 as a standard

@Riyazkhan1989
Copy link

Thanks.

@andersbp
Copy link

Hi and thanks for the script - good work.

I look after an option so I can send output from the script to the browser. I think about the following:

  1. If SSL is not activated when the webpage is loaded the script should write "Your connection is not sure"
  2. If SSL is activated when the webpage is loaded the script should write "Your connection is sure".

I will be glad if someone here please can give me the trick regarding what I should add to the script.

Thanks in advance for your answer, and have a nice day.

Regards,
Anders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment