2012-08-30 101 views
-2

可能重複:
How To Find Out If You are Using HTTPS Without $_SERVER['HTTPS']
PHP Get Site URL Protocol - http vs https如何在php中獲取協議?

我怎樣才能獲得在PHP的協議?

$_SERVER['SERVER_PROTOCOL'] 

顯示我的HTTP/1.1,但有什麼辦法只是回聲http或https?

+0

http://stackoverflow.com/questions/5013633/identify-whether-the-current-url-is-http-or-https-in-a-project?rq=1 – PeeHaa

+0

的http:// stackoverflow.com/questions/7431313/php-getting-full-server-name-including-port-number-and-protocol – PeeHaa

回答

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

如果你真的只是想知道它是否啓用HTTPS或沒有,你可以只使用$_SERVER['HTTPS']

0
list($protocol) = explode("/",$_SERVER['SERVER_PROTOCOL']);