我想用php编写的彩票检查页面。该代码不适用于匈牙利彩票数据库($ url2),但适用于其他($ url1)。问题太多了?
<?php
echo "CURL - function test <br>";
$url1 = "http://www.example.com";
$url2 = "https://bet.szerencsejatek.hu/cmsfiles/otos.html";
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
echo curl_download($url2);
echo strlen(curl_download($url2));
答案 0 :(得分:0)
首先取决于错误是什么。
我认为你应该抛弃CURL工作的结果。像
这样的东西 if (!curl_errno($ch)) {
switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
case 200: # OK
$return = ['result' => 'ok', 'response_text' => $result];
break;
default:
$return = ['result' => 'unexpected_http_code', 'http_code' => $http_code,
'response_text' => $result
];
}
} else {
$return = ['result' => 'curl_error', 'curl_error' => curl_error($ch)];
}
也许是因为您没有配置您的SSL设置,因为第二个网址以https://
开头