0

I'm trying to get an html markup of google.com using curl in php. I write the following:

$ch= curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.google.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$output= curl_exec($ch);
curl_close($ch);
return $output;

The following markup is displayed:

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD>
<BODY>
    <H1>302 Moved</H1>
    The document has moved
    <A HREF="http://www.google.ru/?gfe_rd=cr&amp;ei=xwX7UuzqNuuk4ATU0YHACQ">here</A>.
</BODY>
</HTML>

Now I'm changed php code to the following:

$ch= curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.google.ru/?gfe_rd=cr&amp;ei=xwX7UuzqNuuk4ATU0YHACQ");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$output= curl_exec($ch);
curl_close($ch);
return $output;

But it doesn't work. $output doesn't contains markup of google.com. How to fix this?

mrjimoy_05
  • 3,452
  • 9
  • 58
  • 95
  • So what *does* `$output` contain? – Phil Feb 12 '14 at 05:31
  • @Phil output contains nothing. –  Feb 12 '14 at 05:34
  • Try just curl-ing http://www.google.ru/ without the additional parameters. They are causing another redirect to fire. If that doesn't work, try running curl in the command line and see what you get for the same URL. – dethtron5000 Feb 12 '14 at 05:38
  • @dethtron5000 If execute curl_exec($ch) without returntransfer parameter then it work fine. –  Feb 12 '14 at 05:41

0 Answers0