2014-07-06 141 views
-1

你好我正在開發一個腳本,我需要一些幫助。PHP檢查一個網站是否使用HTTPS

我的問題是我想補充一點,將覈實,如果一個網站使用HTTPS或HTTP的功能。

我的代碼...

$domain = trim(_GET("domain", "", true)); 
if(substr($domain, 0, 7) == "http://") 
    $domain = substr_replace($domain, "", 0, 7); 
$url = "http://" . $domain; 

我想$url成爲http://https://,例如,當我在我的輸入鍵入文本google.com,使其https://google.com,而不是http://google.com

+1

什麼是您的問題或任務離子?這個代碼不工作嗎?如果不是,它做什麼? – deceze

+0

我的代碼是HTTP唯一的工作:如果我輸入google.com例如//(不包含http://或www。)正在此字符串$ URL = HTTP:// gooogle.com,但正確的鏈接應該是$ URL = https://開頭google.com – user3810205

回答

1

可以檢查端口443(SSL)是否打開

$domain = trim(_GET("domain", "", true)); 
if(substr($domain, 0, 7) == "http://") 
    $domain = substr_replace($domain, "", 0, 7); 

if($fp = fsockopen($domaine,443,$errCode,$errStr,1)){ 
    $url = "https://" . $domain; 
} else { 
    $url = "http://" . $domain; 
} 
fclose($fp); 
+0

當然,應該工作,但我需要我的代碼來實現你的代碼,因爲我要檢查遠程網站鏈接,在我的情況$域 – user3810205

+0

與$域名替換$主機:)做你的邏輯代替意見 –

+0

好吧,我已經加入正是你爲我提供的代碼,但現在所有的鏈接變成https://開頭... – user3810205