How To Detect If Url Is Secured Ssl With Php In Https - Tutorial And Guides

Forums » Tutorial And Guides » How To Detect If Url Is Secured Ssl With Php In Https
This Page Contains information about How To Detect If Url Is Secured Ssl With Php In Https - Tutorial And Guides By wallpaperama with 5 Replies. Last Upated: Fri Apr 11, 2014

$_SERVER['HTTPS']



if you want to know if you are using a secured url using port 443 within your site, you can use $_SERVER['HTTPS'], if you are using it will display on

echo $_SERVER['HTTPS'];

this way you can check if your page is using https or http

hope that helps

here is an example of how you can use it

<?php
if($_SERVER['HTTPS']){
echo 'you are secured';
}else{
echo 'you are not secured';
}
?>

try it
Jeff
not every apache and mod-ssl server uses this server variable, one of the ones i have access to does not have any ssl variables so detecting it is impossible on that one
http://wallpaperama.com/forums/how-to-detect-if-url-is-secured-ssl-with-php-in-https-t6935.html
Jeff
you can make an assumption based on your own uploads about the port number however, assuming you use the standard port 443 as your ssl port, you can check to see if $_server["server_port"] does in fact equal 443 -- which is most likely being used for ssl so it is a good backup choice
Nate
it’s not safe to do it this way. some web servers will set $_server['https'] to 'off' when ssl is not being used. it’s better to test for $_server['https'] == 'on'.
web31337
This is not working by default in nginx php(fastcgi) and that code will issue notice if in max error_reporting mode.
If you want to check if it is SSL-connected you may wish to add the following line to your fastcgi params list:

[code]fastcgi_pa HTTPS $ssl_protocol;[/code]

$ssl_cipher variable instead of $ssl_protocol.
HTH.
web31337
FIX:
code is
fastcgi_param HTTPS $ssl_protocol;

for some reason "param" was truncated... maybe my fault.
Title: How To Detect If Url Is Secured Ssl With Php In Https - Tutorial And Guides [1481]
Tags: how to detect if url is secured ssl with php in https
By , 5 Comments