How to check if a page is a call with http or https in php

Just wondering if it is possible, we can check if the page is a call from http or https in php?

Example: If I call the customer.php page at the following link http: //customer.php , it will be possible to check php and report that the page is from http .. also if I call the page from the following link https: //customer.php , it will be possible to check php and report that the page is from https ??

+3
source share
3 answers

Try to see:

if (!empty($_SERVER['HTTPS'])) {
    // https is enabled
}
+10
source

you can also check $_SERVER['SERVER_PORT']how here

HTTP-URL, "http://" 80 URL- HTTPS "https://" 443 .

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
    // do stuff
   }
+1

If the request was sent using HTTPS, you will have an additional parameter in $_SERVERsuperglobal - $_SERVER['HTTPS'].. You can check if it is installed or not.

if( isset($_SERVER['HTTPS'] ) ) {
0
source

All Articles