[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.

<?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".

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

0 Response to "[PHP] Get Site URL Protocol "HTTP or HTTPS""

Post a Comment