如果它是由URL重定向才看到下面的代码,我已经证明它给你,让你可以直接轻松地使用它&,你已经两个主要的卷曲选项控制URL重定向(CURLOPT_FOLLOWLOCATION/CURLOPT_MAXREDIRS):
// create a new cURL resource
$ch = curl_init();
// The URL to fetch. This can also be set when initializing a session with curl_init().
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
// The contents of the "User-Agent: " header to be used in a HTTP request.
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0");
// TRUE to include the header in the output.
curl_setopt($ch, CURLOPT_HEADER, false);
// TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION.
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
// grab URL and pass it to the output variable
$output = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
// Print the output from our variable to the browser
print_r($output);
上述代码处理URL重定向问题,但它不处理cookie(您的本地主机URL似乎是处理cookie)。如果要对付来自卷边资源饼干,那么你可能得给下面卷曲选项一看: CURLOPT_COOKIE CURLOPT_COOKIEFILE CURLOPT_COOKIEJAR
欲了解更多详情,请按照下面的链接: http://docs.php.net/function.curl-setopt
如果你用四个空格缩进你的代码,它会更具可读性。 – 2010-04-02 08:49:21