There are no php.ini configurations for $_SERVER['HTTPS']
. This key is set to a non-empty value only if the request was made over HTTPS. Meaning, if (!empty(filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN))) { /* request was made over https */ }
.
See the manual for more details...
'HTTPS'
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.
filter_var
with FILTER_VALIDATE_BOOLEAN
will return a boolean false
when this value is "0"
, "false"
, "off"
, "no"
, ""
, or NULL
.
Keep In mind
It's also important remember that PHP only populates $_SERVER['HTTPS']
from information it obtains through the SAPI (Server API) that it uses to communicate with your web server software. So this could be mod_php, or fcgi, etc... Typically this data gets populated from environment variables that PHP copies from your web server through the SAPI. By default Apache httpd will include the HTTPS environment variable when the connection is made over HTTPS, however nginx will not if you're using fastcgi_pass
. You need to configure this yourself by modifying your nginx config to set a fastcgi_param
for HTTPS
. This will allow nginx to notify php-fpm of the environment variable over fastcgi and it can be populated in your PHP accordingly.
Also note, that this can be made even more complicated if you're using nginx as a reverse proxy since the reverse proxy will also have to pass along the information to the proxied node the same way.
Important Note
However, you should note that using PHP to redirect to HTTPS by default is probably a bad idea. It's better to configure your webserver to do this instead.
For example, in Apache httpd you can configure your VHOST to redirect all HTTP traffic to HTTPS by default, which probably going to be safer and easier in case you happen to forget this in some PHP end-point. That is assuming your intentions here are to enforce HTTPS across your entire site or some specific domain.