0

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

4 Answers 4

7
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
    // do your stuff here...
Sign up to request clarification or add additional context in comments.

3 Comments

is there some time that it will be != 'off' AND != 'on'?
Yes. IIS with ISAPI. See Mauris' answer.
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.
3

$_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.

Comments

1
$_SERVER['HTTPS'] == 'on'

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

Comments

0

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

1 Comment

I don't have this var in my $_SERVER, why ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.