lovespring
lovespring

Reputation: 19569

How to know php script is request in HTTPS not HTTP?

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

Upvotes: 0

Views: 230

Answers (4)

joseph
joseph

Reputation: 16

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

Upvotes: 0

Franz
Franz

Reputation: 11553

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
    // do your stuff here...

Upvotes: 7

mauris
mauris

Reputation: 43619

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

Upvotes: 3

x2.
x2.

Reputation: 9668

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

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

Upvotes: 1

Related Questions