Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: HTTP or HTTPS? [duplicate]

Tags:

php

How can I tell if a php page was accessed via http or https?

like image 815
sachidanand Avatar asked Oct 28 '10 12:10

sachidanand


3 Answers

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'] ) ) {
like image 141
Eran Galperin Avatar answered Nov 03 '22 08:11

Eran Galperin


If your request is sent by HTTPS you will have an extra server variable named 'HTTPS'

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { //HTTPS } 
like image 47
Aelios Avatar answered Nov 03 '22 08:11

Aelios


$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https'?'https':'http';

$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';

These should both work

like image 27
Mark Baijens Avatar answered Nov 03 '22 10:11

Mark Baijens