What's best way to know if server was accessed by HTTP or HTTPS?



With Apache and PHP, what’s the best way to know it, and to force using HTTPS?

I searched in phpinFO() for $_SERVER variables and found nothing that could help.

Edit: thanks for answers and suggestions! I can’t force it on server level because it’s only for login page.


$_SERVER['HTTPS'] is non-empty if HTTPS was used. But you’d be better off doing the HTTPS enforcement at the webserver level, e.g.

<virtualhost example.com:80>
   redirect permanent https://example.com

<virtualhost example.com:443>
   blah blah blah

Answered By – Marc B

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More