2014-08-29 63 views
1

我正在运行XML到PHP安装的付费谷歌网站搜索。Azure不会卷曲一个谷歌网站搜索xml

https://code.google.com/p/google-csbe-example/downloads/detail?name=gss.php&can=2&q=

我初步实现完美运行在LAMP服务器上,但是我现在必须运行Windows Azure平台上的PHP环境。

看起来好像$url变量没有通过cURL传递,因为$result变量返回值为NULL

$url = 'https://www.google.com/cse?cx=' . $your_cx_number . '&client=google-csbe&output=xml_no_dtd&q=' . $q; 
if(isset($start)){ 
    $url .= '&start=' . $start; 
} 

如果我修改的$url值到不同的远程xml文件,用少许调整产出结构,我得到预期的结果。

我曾尝试几种不同的故障处理步骤,包括:

  • 卷曲:备用XML饲料呈现
  • simplexml的:交替RSS频道呈现
  • 权限:网站权限不需要谷歌CSE仪表板
  • 替代天青网站:测试和失败
  • 备用LAMP托管网站:测试成功
  • 备用搜索设置:这是没有效果的
  • 是阻止谷歌域名:不这么认为
  • 网址查询阻止:这是否是引起任何问题

我难倒不知道。

任何帮助将不胜感激。 谢谢!

下面是完整的代码(减去CX号):

<?php 
//ini_set('display_startup_errors',1); 
//ini_set('display_errors',1); 
//error_reporting(-1); 

$q = $_GET['q']; 
$q = urlencode($q); 

//WRAPPED IN A IF STATEMENT SO PROMOTED RESULTS SHOW UP ON THE FIRST PAGE 
if(isset($_GET['start'])){ 
    $start = $_GET['start']; 
} 

$your_cx_number = 'enter_your_paid_google_site_search_cx_number'; 

$url = 'https://www.google.com/cse?cx=' . $your_cx_number . '&client=google-csbe&output=xml_no_dtd&q=' . $q; 
if(isset($start)){ 
    $url .= '&start=' . $start; 
} 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_FAILONERROR, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);// allow redirects 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return into a variable 
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s 
curl_setopt($ch, CURLOPT_HTTPGET, true); // set POST method 
//curl_setopt($ch, CURLOPT_POSTFIELDS, "postparam1=postvalue"); // add POST fields 

//submit the xml request and get the response 
$result = curl_exec($ch); 
curl_close($ch); 

//now parse the xml with 
$xml = simplexml_load_string($result); 
$START = $xml->RES['SN']; 
$END = $xml->RES['EN']; 
$RESULTS = $xml->RES->M; 

?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Search results</title> 
</head> 
<body> 
<form action="search-test.php" id="searchform" > 
    <input type="text" name="q" placeholder="Search..." <?php if(isset($_GET['q'])) { echo 'value="' . $_GET['q'] . '"' ; }?> id="search-text" size="25" autocomplete="off" /> 
    <input type="submit" id="search-button" title="Search" value="" /> 
</form> 
<p>The url of the <a href="<?php echo $url ?>">XML output</a></p> 
    <?php 
//extract the title, link and snippet for each result 
if ($xml->RES->R) { 
    foreach ($xml->RES->R as $item) { 
     $title = $item->T; 
     $link = $item->U; 
     $snippet = $item->S; 
     echo '<h3><a href="' . $link . '">' . $title . '</a></h3> 
       <p><a href="' . $link . '">' . $title . '</a></p> 
       <p>' . $snippet . '</p> 
       <hr />'; 
    } 
} 
?> 
</body> 
</html> 

回答

1

卷曲错误报告返回错误代码:60

Curl error: 60 - SSL certificate problem: unable to get local issuer certificate

一种类似的错误搜索所提供的解决方案 HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK

加入该行:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 

全卷曲功能现在是:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($ch, CURLOPT_FAILONERROR, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);// allow redirects 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return into a variable 
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s 
curl_setopt($ch, CURLOPT_HTTPGET, true); // set POST method 

$result = curl_exec($ch); 
if(curl_errno($ch)){ 
     echo 'Curl error: ' . curl_errno($ch) . ' - ' .curl_error($ch); 
     $info = curl_getinfo($ch); 
     if (empty($info['http_code'])) { 
      die("No HTTP code was returned"); 
     } else { 
       echo $info['http_code']; 
     } 
} 
curl_close($ch);