PHP implements http and https conversion_PHP tutorial

WBOY
Release: 2016-07-13 17:45:08
Original
782 people have browsed it

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!