小编Shi*_*hur的帖子

使用CURL检查网站是否正在使用SSL

我正在构建一个脚本,该脚本将检查网站是否正在使用SSL。例如,我们使用“ http://www.google.com/ ”,它将被重定向到“ https://www.google.com/ ”。我该如何检查?我正在使用以下cURL代码来获取网站的标头。

<?php
$url = 'https://www.google.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // set url
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); // set browser/user agent
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); // get header
curl_exec($ch);

function read_header($ch, $string) {
    print "Received header: $string";
    return strlen($string);
}
?>
Run Code Online (Sandbox Code Playgroud)

输出:

HTTP/1.1 302 Found 
Cache-Control: private 
Content-Type: text/html; charset=UTF-8 
Location: https://www.google.co.in/?gfe_rd=cr&ei=YEAkV7SEFrTv8wexyy0 
Content-Length: 259 
Date: Sat, 30 Apr 2016 05:19:28 GMT 
Alternate-Protocol: …
Run Code Online (Sandbox Code Playgroud)

php ssl curl

6
推荐指数
1
解决办法
4863
查看次数

标签 统计

curl ×1

php ×1

ssl ×1