簡體   English   中英

如何檢查頁面是否從 php 中的 http 或 https 調用

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

只是想知道,是否有可能我們可以檢查該頁面是否是從 php 中的 http 或 https 調用的?

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鏈接https://customer.php ,是否可以檢查 php 並告訴頁面來自 Z5076A56C01BADE50A18

試着看看:

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

您還可以檢查此處所寫$_SERVER['SERVER_PORT']

與以“http://”開頭並默認使用端口 80 的 HTTP URL 不同,HTTPS URL 以“https://”開頭並默認使用端口 443。

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

如果請求是使用 HTTPS 發送的,那么$_SERVER超全局變量中將有一個額外的參數- $_SERVER['HTTPS']. 您可以檢查它是否已設置

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM