Curl with Cookies and Proxy
Posted: Tue Jan 05, 2010 1:03 pm
I am trying to login to a page that requires cookies from a previous page with the curl request and therefore I am passing cookie4.txt on line 5 below. I have saved this while accessing the previous page and the cookies are there. Then I am saving any new cookies in cookies5.txt for future work if needed.
The page I am accessing at $url has a redirect (I am not sure how i.e meta or what) to another page. So when accessing that page at $url with cookies4.txt below I would like to follow the redirect link and get to the last page i am redirected to.
The last thing is that I am trying to do this through a proxy so I am anon.
So far I am able to get the page at $url as my output at $data so I don't think I was able to follow the redirect. According to my test I am appearing as anon through the proxy I am using.
Any help is greatly appreciated.
$ch = curl_init();
curl_setopt ($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1); // no headers in the output
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie4.txt');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie5.txt');
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // output to variable
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
$data = curl_exec($ch);
curl_close($ch);
The page I am accessing at $url has a redirect (I am not sure how i.e meta or what) to another page. So when accessing that page at $url with cookies4.txt below I would like to follow the redirect link and get to the last page i am redirected to.
The last thing is that I am trying to do this through a proxy so I am anon.
So far I am able to get the page at $url as my output at $data so I don't think I was able to follow the redirect. According to my test I am appearing as anon through the proxy I am using.
Any help is greatly appreciated.
$ch = curl_init();
curl_setopt ($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1); // no headers in the output
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie4.txt');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie5.txt');
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // output to variable
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
$data = curl_exec($ch);
curl_close($ch);