php curl来检查ssl连接 [英] php curl to check ssl connection

查看:184
本文介绍了php curl来检查ssl连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意

b>:未定义索引:主机位于 6 行上的 C:\ xampp\htdocs\labs\test2\get.php

错误:3个格式错误

Notice: Undefined index: host in C:\xampp\htdocs\labs\test2\get.php on line 6
Error:3 malformed

AJAX代码:

    var hostName = $("input#host").val();
dataString = hostName;

$.ajax({
    type: "GET",
    url: "get.php",
    data: dataString,
    dataType: "json",

PHP CURL代码:

PHP CURL code:

<?php
if($fp = tmpfile())
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $_GET['host']);
    curl_setopt($ch, CURLOPT_STDERR, $fp);
    curl_setopt($ch, CURLOPT_CERTINFO, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
    $result = curl_exec($ch);
    curl_errno($ch)==0 or die("Error:".curl_errno($ch)." ".curl_error($ch));
    fseek($fp, 0);//rewind
    $str='';
    while(strlen($str.=fread($fp,8192))==8192);
    echo $str;
    fclose($fp);
}
?>

- RESPONSE

-- RESPONSE ---


HTTP / 1.1 302找到Cache-Control:private Content-Type:text / html; charset = UTF-8位置: http://www.google.com.au /?gfe_rd = cr& ei = VbwrVa_RFsPu8wfN54HYBQ Content-Length:262 Date:Mon,13 Apr 2015 12:53:41 GMT服务器:GFE / 2.0替代协议:80:quic,p = 0.5 * to:www.google.com/ *在DNS缓存中找不到主机名*尝试216.58.220.100 ... *已连接到www.google.com(216.58.220.100)端口80(#0)> HEAD / HTTP / 1.1主机:www.google.com接受: / < HTTP / 1.1 302 Found<高速缓存控制: Content-Type:text / html; charset = UTF-8<位置: http://www.google.com.au/?gfe_rd=cr& ; ei = VbwrVa_RFsPu8wfN54HYBQ Content-Length:262<日期:星期一,2015年4月13日12:53:41 GMT<服务器:GFE /替代方案:80:quic,p = 0.5 < * Connection#0 to host www.google.com left intact

HTTP/1.1 302 Found Cache-Control: private Content-Type: text/html; charset=UTF-8 Location: http://www.google.com.au/?gfe_rd=cr&ei=VbwrVa_RFsPu8wfN54HYBQ Content-Length: 262 Date: Mon, 13 Apr 2015 12:53:41 GMT Server: GFE/2.0 Alternate-Protocol: 80:quic,p=0.5 * Rebuilt URL to: www.google.com/ * Hostname was NOT found in DNS cache * Trying 216.58.220.100... * Connected to www.google.com (216.58.220.100) port 80 (#0) > HEAD / HTTP/1.1 Host: www.google.com Accept: / < HTTP/1.1 302 Found < Cache-Control: private < Content-Type: text/html; charset=UTF-8 < Location: http://www.google.com.au/?gfe_rd=cr&ei=VbwrVa_RFsPu8wfN54HYBQ < Content-Length: 262 < Date: Mon, 13 Apr 2015 12:53:41 GMT < Server: GFE/2.0 < Alternate-Protocol: 80:quic,p=0.5 < * Connection #0 to host www.google.com left intact


推荐答案

http_build_query不创建一个有效的网址,但只格式化您的GET请求的参数数组。
你应该这样做:

http_build_query does not create a valid url but only formats the parameters array for your GET request. You should do something like :

$url = "https://".$_REQUEST['host']."?"."{$query_string}";

在您的示例中,生成的url将是

In your example the resulting url will be

https://www.google.com?host=www.google.com

请注意https

这篇关于php curl来检查ssl连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆