[PHP] Get Site URL Protocol "HTTP or HTTPS"


[PHP] Get Site URL Protocol "HTTP or HTTPS"


[PHP] Get Site URL Protocol "HTTP or HTTPS" - In this case, some PHP developers need to check the protocol of the site is using HTTP or  HTTPS. For example: on local server still using HTTP protocol while on the online server is using HTTP protocol.

So, the developers need to determine a variables that need HTTP or HTTPS. Below is the sample code for determine it.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
        // checking $protocol in HTTP or HTTPS
        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
            // this is HTTPS
            $protocol  = "https";
        } else {
            // this is HTTP
            $protocol  = "http";
        }
?>

Done, it is a sample code for [PHP] Get Site URL Protocol "HTTP or HTTPS".

You need to know:

  1. Getting Started With Accelerated Mobile Pages (AMP) HTML
  2. [PHP] How to Replace a String in PHP


Paper 4Share - [PHP] Get Site URL Protocol "HTTP or HTTPS"

loading...