Recently in the PHP program, you need to make the browser between HTTPS and HTTP conversion, Internet search related information, but only recently in the PHP program, need to make the browser between HTTPS and HTTP conversion, Internet search related information, but only one introduction with ASP implementation " "Between HTTP and https" article, so had to write the PHP implementation of HTTP and HTTPS conversion code.
If the Web page uses HTTPS access, add the following code at the beginning of the page:
<?php //http converted to HTTPS if ($_server["https"]<> "on") { $xredir = "https://". $_server[" SERVER_NAME "]. $_server["Request_uri"]; Header ("Location:". $xredir); } ? >
If the Web page uses HTTP access, add the following code at the beginning of the page:
<?php //https translates to HTTP if ($_server["HTTPS"]== "on") { $xredir = "http://". $_server["Server_ NAME "]. $_server["Request_uri"]; Header ("Location:". $xredir); } ? >
PHP determines whether HTTP or HTTPS, and how to get the current URL
$http _type = ((Isset ($_server[' https ") && $_server[' https '] = = ' on ') | | (Isset ($_server[' Http_x_forwarded_proto ') && $_server[' http_x_forwarded_proto '] = = ' https ')) ? ' https://': '/http '; Echo $http _type. $_server[' Http_host '. $_server[' Request_uri '];?>
PHP for HTTP and HTTPS conversions