php cURL bot redirect issue
304
function Baglan($url) {
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6';
$ct = curl_init();
curl_setopt($ct, CURLOPT_URL, $url);
curl_setopt($ct, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ct, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ct, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ct, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ct, CURLOPT_COOKIEFILE, "cookies.txt");
$cikti = curl_exec($ct);
curl_close($ct);
return str_replace(array("\n", "\t", "\r",), null, $cikti);
}
include ('mysql.php');
mysql_query("SET NAMES 'utf8'");
$baglan = Baglan("http://www.example.net/");
echo $baglan; //when I plug echo command, I see this redirect code: <html><body><script>document.cookie="nekil=bb1aecfdbe52cc1be231de5ba04a4c3d";location.href="http://www.example.net/";</script></body></html>
/*preg_match('#<div data-view="grid-mini">
<div >(.*?)</div>
</div><!-- end .loop-content -->#', $baglan, $videolar);
print_r($videolar); <!-- Its not see real codes becouse of redirect issue becouse of that when I plug to work this function i see only Array() at the page -->*/
Please read the descriptons of the code side(up there). How can I reach to real codes of site?
Answer
Solution:
You have to parse url and cookie value from the response, then perform 2nd request to the parsed url with cookie set to parsed value. So the code should look like this: