How can I tell if a php page was accessed via http or https?
http://www.php.net/manual/en/reserved.variables.php#74040
You could also have Googled. This one even has the same title as your question - http://bytes.com/topic/php/answers/488284-php-http-https-how-can-one-tell
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https'?'https':'http';
$protocol = isset($_SERVER["https"]) ? 'https' : 'http';
These should both work
If the request was sent with HTTPS you will have a extra parameter in the $_SERVER superglobal - $_SERVER['HTTPS']. You can check if it is set or not
if( isset($_SERVER['HTTPS'] ) ) {
$_SERVER['HTTPS']
This will contain a 'non-empty' value if the request was sent through HTTPS
You should be able to do this by checking the value of $_SERVER['HTTPS']
(it should only be set when using https).
This can get more complicated depending on where PHP sits in your environment, since your question is quite broad. This may depend on whether there's a load-balancer and how it's configured. Here are are a few related questions: