2017-05-17 83 views
1

我有一個腳本,檢查當前頁面的SSL,但我需要它的工作,所以當用戶輸入一個URL到表單並點擊提交按鈕,它會請回復說「你輸入的URL具有SSL」,或者如果沒有,則返回「本網站沒有SSL」。檢查表單提交的URL是否具有HTTPS

這裏是我的PHP代碼:

if (!empty($_SERVER['HTTPS'])) { 
 
      echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>"; 
 
     }else{ 
 
      echo '<p>Good job, this page has SSL.</p>'; 
 
     }

在此先感謝。

+0

所以你只是想檢查他們輸入的域是否以'https'開頭? – BizzyBob

+0

的確如此,但它會很酷,如果它會檢查HTTPS的HTTP服務器狀態與否。 –

回答

0

看來,你允許用戶查看他們的網站,基於這一點,你可以使用:

$url = parse_url('https://user.url'); 
if($url['scheme'] == 'https') 
{ 
    echo '<p>Good job, this page has SSL.</p>'; 
}else{ 
    echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>"; 
} 

OLD答案 - 並不適用於任擇議定書的答案,但可以有用的檢查當前的URL是使用HTTPS:

if ($_SERVER['REQUEST_SCHEME'] == "https") 
{ 
    echo '<p>Good job, this page has SSL.</p>'; 
}else{ 
    echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>"; 
} 

您還可以使用:

if (isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS']) 
{ 
    echo '<p>Good job, this page has SSL.</p>'; 
}else{ 
    echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>"; 
} 

最後一個選項似乎是確定https最安全的方法。

+0

當然,謝謝。但是,不是最後一個獲取當前頁面的HTTP/HTTPS狀態,而不是從表單中請求的URL?乾杯。 –