Home  >  Article  >  Backend Development  >  PHP implements http and https conversion_PHP tutorial

PHP implements http and https conversion_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:45:08784browse

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);

}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478700.htmlTechArticleWhen writing a PHP program recently, I need to make the browser convert between https and http, and search for relevant information online. Unfortunately, when writing PHP programs recently, I need to make the browser switch between https and http...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn