PHP curl问题从url读取数据

时间:2017-03-29 09:22:23

标签: php json curl

当我尝试在PHP小提琴中执行以下PHP代码时它工作正常并返回NOT-Empty但是当我通过PHP文件在我的程序中运行完全相同的代码时它返回Empty。不确定我的服务器是否阻止了它?任何建议

<?php
 getCustomerTicketsByPage_1();

function  getCustomerTicketsByPage_1()
{   
$url="https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452";

$ch = curl_init ($url);

curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);

$server_output = curl_exec ($ch);
curl_close ($ch);
$tickets = json_decode($server_output, true);
if(!empty($tickets)){
    echo (" NOT-EMPTY ");
} else {
    echo (" EMPTY ");
}
}


?>

0 个答案:

没有答案