Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP检查网站是否使用HTTPS_Php_Curl_Https - Fatal编程技术网

PHP检查网站是否使用HTTPS

PHP检查网站是否使用HTTPS,php,curl,https,Php,Curl,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://,例如,当我在

你好,我正在开发一个脚本,我需要一些帮助

我的问题是我想添加一个函数来验证网站是否使用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

您可以检查端口443(SSL)是否打开,请参见下文

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

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

你到底有什么问题?这代码不管用吗?如果没有,它做什么/不做什么?我的代码只适用于http://例如,如果我键入google.com(不含http://或www.)将此字符串设置为$url=http://google.com,但正确的链接应该是$url=https://google.com当然可以,但我需要用我的代码实现您的代码,因为我想检查远程网站链接,在我的例子中,$domain将$host替换为$domain:)并用您的逻辑代替commentsOk,我已经添加了您提供给我的代码,但现在所有链接都变成https://…因此它们都支持SSLtry 188.132.173.113端口443已关闭