| Index | Description |
|---|---|
| HTTPS | Returns a non-empty value if the current request is using HTTPS. |
| HTTP_HOST | Returns the host for the current request. |
| REQUEST_URI | Returns the URI (Uniform Resource Identifier) for the current request. |
util/secure_conn.php) that redirects a page to a secure connection
<?php
// make sure the page uses a secure connection
$https = filter_input(INPUT_SERVER, 'HTTPS');
if (!$https) {
$host = filter_input(INPUT_SERVER, 'HTTP_HOST');
$uri = filter_input(INPUT_SERVER, 'REQUEST_URI');
$url = 'https://' . $host . $uri; header("Location: " . $url);
exit();
}
?>
$_SERVER array contains information about headers and paths. This data is set by your web server, and the code above works for most versions of Apache.$_SERVER array the same way. So, if this code doesn’t work for your web server, you need to adjust it so it does.filter_input() function to get the values for the indexes of the $_SERVER array.