How to redirect a page to https in php?
I have a login form:
<form method =POST action="/login.php">
...
</form>
I would like the page login.phpredirected to use https.
I do not want to send the user to https://.../login.php, because they can change the link. but I want to do server-side redirects before parsing the login form data and registering the user.
I found an example:
if($_SERVER["HTTPS"] != "on") {
header("HTTP/1.1 301 Moved Permanently");
header("Location: "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
but i don't $_SERVER["HTTPS"]have if ivar_dump($_SERVER);
I have $_SERVER['SERVER_PORT']witch is 80.
any ideas?
thank
, index.php, HTTP HTTPS index.php. , , /login.php HTTPS, HTTP.
login.php , login.php HTTPS-URL, , , .
, $_SERVER['SERVER_PORT'] 80 $_SERVER["HTTPS"] , login.php, , HTTP , , . , , .
, PHP . mod_rewrite Apache HTTPD.
, , URL-, http://example.com/foo/:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^foo/$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]