Hi,
I am new to PHP and need some help to get past below huddle.
What I am trying to do is read the contents of a webpage. Below program works good for most of the website but fails when the page is redirected to another page.
PHP Code:
function get_url_contents($url){
$crl = curl_init();
$timeout = 10;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($crl, CURLOPT_AUTOREFERER, FALSE);
curl_setopt ($crl, CURLOPT_FOLLOWLOCATION, TRUE);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
$content= get_url_contents("http://www.foo.com");
echo $content;
I tried creating a html link and if I click on that link it does not get redirect but lands on the right page.
<a href ="http://foo.com">Foo</a>
My question is - how can I do this in PHP? I understand that Server is forcing it to re-direct but why is it not doing for HTML code?
Thanks in advance!