3

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

Jin Yong
  • 42,698
  • 72
  • 141
  • 187
  • 1
    possible duplicate of [PHP: HTTP or HTTPS? How can one tell?](http://stackoverflow.com/questions/4042962/php-http-or-https-how-can-one-tell) – Shakti Singh May 24 '11 at 05:15

3 Answers3

10

Try to look at:

if (!empty($_SERVER['HTTPS'])) {
    // https is enabled
}
zerkms
  • 249,484
  • 69
  • 436
  • 539
1

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
   }
xkeshav
  • 53,360
  • 44
  • 177
  • 245
0

If the request was sent with HTTPS you will have a extra parameter in the $_SERVER superglobal - $_SERVER['HTTPS']. You can check if it is set or not

if( isset($_SERVER['HTTPS'] ) ) {
Harsh
  • 2,078
  • 6
  • 22
  • 37