Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the page is call from http or https in php

Tags:

php

Just wondering, will it be possible we can check whether the page is call from http or https in php?

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

like image 880
Jin Yong Avatar asked Mar 20 '26 05:03

Jin Yong


2 Answers

Try to look at:

if (!empty($_SERVER['HTTPS'])) {
    // https is enabled
}
like image 87
zerkms Avatar answered Mar 21 '26 19:03

zerkms


you can also check for $_SERVER['SERVER_PORT'] as written here

As opposed to HTTP URLs that begin with "http://" and use port 80 by default, HTTPS URLs begin with "https://" and use port 443 by default.

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
    // do stuff
   }
like image 29
diEcho Avatar answered Mar 21 '26 19:03

diEcho