Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting SSL With PHP [duplicate]

Tags:

php

https

ssl

Possible Duplicate:
How To Find Out If You are Using HTTPS Without $_SERVER['HTTPS']

I went looking around the web for ways to detect if a server is using an HTTPS connection, but no one site seemed to have all the answers (and some different ones). What exactly are all the ways to detect if a server is using an HTTPS connection with PHP? I need to know several ways to detect SSL as some of my scripts are redistributed and various servers handle things differently.

like image 677
Phillip Avatar asked Sep 05 '11 05:09

Phillip


1 Answers

$_SERVER['HTTPS']

Set to a non-empty value if the script was queried through the HTTPS protocol.
Note: Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol.

http://www.php.net/manual/en/reserved.variables.server.php

Ergo, this'll do:

if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {     // SSL connection } 
like image 90
deceze Avatar answered Oct 18 '22 03:10

deceze