tags:

views:

60

answers:

4

I have checked all $_SERVER member var, still don't know how.

+1  A: 
$_SERVER['HTTPS'] == 'on'

upd: and $_SERVER['SERVER_PROTOCOL'] or $_SERVER['SERVER_PORT'] == 443//80 for http

x2
+3  A: 

$_SERVER['HTTPS'] - from http://php.net/manual/en/reserved.variables.server.php

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.

thephpdeveloper
+5  A: 
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
    // do your stuff here...
Franz
is there some time that it will be `!= 'off'` __AND__ `!= 'on'`?
quack quixote
Yes. IIS with ISAPI. See Mauris' answer.
Franz
Ah, my bad. That comment was actually the right answer, but not to your question, @quack. I don't know of any other case. However, as Mauris' wrote, IIS sets the value to 'off' when using ISAPI which is why the second part of the condition is necessary.
Franz
A: 

if you do print_r($_SERVER); => you can see this. [HTTPS] => on

joseph
I don't have this var in my $_SERVER, why ?
lovespring
That means it's off.
Franz