PHP for HTTP and HTTPS conversions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.