Recently, when writing a PHP program, I need to make the browser convert between https and http, and search for relevant information on the Internet. Unfortunately, only recently when writing a PHP program, I need to make the browser convert between https and http, and search for related information on the Internet. Unfortunately, there was only one article that introduced the use of ASP to implement "conversion between http and https", so I had to write the code to use PHP to implement the conversion between http and https.
If the webpage is accessed using https, add the following code at the beginning of the webpage:
view plainprint?
//Convert http to https
if ($_SERVER["HTTPS"]<>"on")
{
$xredir="https://".$_SERVER["SERVER_NAME"].
$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
?>
If the web page is accessed using http, add the following code at the beginning of the web page:
view plainprint?
//Convert https to http
if ($_SERVER["HTTPS"]=="on")
{
$xredir="http://".$_SERVER["SERVER_NAME"].
$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
?>