I'm new to PHP. I have searched StackOverflow and followed instructions from answers to similar questions. However, the instructions are not working for me.
This is the issue:
I'm trying to fetch HTML using PHP cURL for parsing.
http://actas.rfef.es/actas/NPortada
This is a publicly-accessible page. When I request the page through a browser's address bar, it works fine. However, if the request is through cURL, I'm redirected to http://actas.rfef.es/actas/NLogin (0 byte blank page).
I thought useragent may be an issue and set curl's user agent value and followlocation
to false,but still it redirects!
Here is my code:
$home="http://actas.rfef.es/actas/NPortada";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$home);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER, TRUE);
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:18.0)Gecko/20100101 Firefox/18.0");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch,CURLOPT_COOKIEJAR, "cookies.txt");
echo curl_exec($ch);
curl_close($ch);
Why does it redirect, even though followLocation
is set to false
? There are no meta refresh tags in that target page.
How can I avoid being redirected and get the html of the targeted page? What am I doing wrong?
I've been struggling with this problem for the last 3 days. Please will anyone help me with this? Thanks in advance.