-2

Possible Duplicate:
How To Find Out If You are Using HTTPS Without $_SERVER['HTTPS']
PHP Get Site URL Protocol - http vs https

How i can get the protocol in php?

$_SERVER['SERVER_PROTOCOL']

shows me the HTTP/1.1 but is there is any way to just echo http or https?

Community
  • 1
  • 1
baig772
  • 3,404
  • 11
  • 48
  • 93
  • http://stackoverflow.com/questions/5013633/identify-whether-the-current-url-is-http-or-https-in-a-project?rq=1 – PeeHaa Aug 30 '12 at 18:08
  • http://stackoverflow.com/questions/7431313/php-getting-full-server-name-including-port-number-and-protocol – PeeHaa Aug 30 '12 at 18:10

2 Answers2

1
$protocol = current(explode('/',$_SERVER['SERVER_PROTOCOL']));

If you really just want to know if it HTTPS is enabled or not, you can just use $_SERVER['HTTPS'].

kba
  • 19,333
  • 5
  • 62
  • 89
0
list($protocol) = explode("/",$_SERVER['SERVER_PROTOCOL']);