3

Possible Duplicate:
PHP: HTTP or HTTPS? How can one tell?

Is there a way to define this?

$_SERVER superglogal doesn't provide such info. Even only it's ['SERVER_PROTOCOL'] ...

Community
  • 1
  • 1
s.webbandit
  • 16,332
  • 16
  • 58
  • 82

1 Answers1

5

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

if( isset($_SERVER['HTTPS'] )  && $_SERVER['HTTPS'] != 'off' ) 
{
   echo 'HTTPS';
}
else
{
  echo 'HTTP';
}
Aelios
  • 11,849
  • 2
  • 36
  • 54
  • One little problem here. Elements of `$_SERVER` are generated by the web server, so it maybe missing `https` entry because server does not generate one while requested over `https://`. – Leri Oct 22 '12 at 10:12
  • 2
    **Note** that when using ISAPI with IIS, the value will be *'off'* if the request was not made through the HTTPS protocol, so the test should be `isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'` to be cross-api. – pozs Oct 22 '12 at 10:13