errorno(),但cURL已安装并可用
我试图得到cURL错误号,但curl_errorno()
函数似乎不起作用。 如果我制作一行脚本:
curl_errorno();
我得到这个错误:
调用未定义的函数curl_errorno()...
--with-curl
任何想法为什么curl_errorno()
不可用?
curl_errno();
不
curl_errorno();
http://www.jonasjohn.de/snippets/php/curl-example.htm
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, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
要使用它...
print curl_download('http://www.example.org/');
也许试试看,如果它有效,也许它是你以前的代码的问题?
如果您有任何CURL或CURL扩展问题,请不要在您的服务器上安装,然后再使用下面的代码
function get_web_page( $url )
{
$options = array( 'http' => array(
'user_agent' => 'spider', // who am i
'max_redirects' => 10, // stop after 10 redirects
'timeout' => 120, // timeout on response
) );
$context = stream_context_create( $options );
$page = @file_get_contents( $url, false, $context);
$result = array( );
if ( $page != false )
$result['content'] = $page;
else if ( !isset( $http_response_header ) )
return null; // Bad url, timeout
// Save the header
$result['header'] = $http_response_header;
// Get the *last* HTTP status code
$nLines = count( $http_response_header );
for ( $i = $nLines-1; $i >= 0; $i-- )
{
$line = $http_response_header[$i];
if ( strncasecmp( "HTTP", $line, 4 ) == 0 )
{
$response = explode( ' ', $line );
$result['http_code'] = $response[1];
break;
}
}
return $result;
}
链接地址: http://www.djcxy.com/p/57743.html