Reputation: 2383
I have sort php code using curl for get a web page.
$url = "http://google.com";
$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
exit;
and here is the full reponse from google.
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
But now i don't want CURL get full page from google, i just want get response from <HTML>
to <H1>301 Moved</H1>
and stop curl response and close connection.
Anyone can help me to do this?
Upvotes: 0
Views: 280
Reputation: 180147
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
will have cURL follow any 301/302 redirects.
Upvotes: 1