I wanna put the content of a URL in a string and the process it. However, I have a problem.
I get this error:
Warning: file_get_contents(http://www.findchips.com/avail?part=74ls244) [function.file-get-contents]: failed to open stream: Redirection limit reached,
I have heard this comes due to page protection and headers, cookies and stuff. How can I override it?
I also have tried alternatives such as fread along with fopen but I guess I just don't know how to do this.
Can anyone help me please?
This question is related to
php
url
curl
file-get-contents
Use cURL
,
Check if you have it via phpinfo();
And for the code:
function getHtml($url, $post = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if(!empty($post)) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Try using cURL instead. cURL implements a cookie jar, while file_get_contents doesn't.
original answer moved to this topic .
Source: Stackoverflow.com