I want to redirect users of my site from http://mysiteto https://mysite.
http://mysite
https://mysite
How can I do this programmatically in PHP?
If $_SERVER['HTTPS']set to on, the page loads via https. However, you must mark your cookies as safe, which you can do with one of the options setcookie. If cookies are not protected, they can be transmitted via unencrypted http and can be stolen even if the user is redirected immediately.
$_SERVER['HTTPS']
on
setcookie
http://php.net/manual/en/function.setcookie.php
.htaccess, PHP. .htaccess .
RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteCond ^(.*)$ https://www.example.com/$1 [R=301,L]
, SSL if(!empty($_SERVER['HTTPS'])).
if(!empty($_SERVER['HTTPS']))
, $_SERVER['SERVER_PORT'] == 443, , , HTTPS , , SSL .
$_SERVER['SERVER_PORT'] == 443
PHP, .htaccess( Apache):
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Use $_SERVER['HTTPS']to define.
If https, then the variable $_SERVER['HTTPS']will be set to a non-zero value:
if (isset($_SERVER['HTTPS'])) { # it https } else { # it not https }