Re: Using PHP to retrieve a Yahoo Groups Web Page

From: Date: Fri, 06 Jul 2007 15:31:29 +0000
Subject: Re: Using PHP to retrieve a Yahoo Groups Web Page
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-258421@lists.php.net to get a copy of this message
Greg Donald wrote:
On 7/4/07, Alan Milnes <alan@itfoundation.org.uk> wrote:
I have spent the afternoon trawling the web for how to retrieve a Yahoo Groups Web Page using PHP. The best option seems to be curl, which is installed on my host. I need to understand how to set the cookies so that Yahoo accepts my response. The code I have is:- $url="http://uk.groups.yahoo.com/group/gameplan/message/17162"; $c = curl_init ($url); curl_setopt ($c, CURLOPT_VERBOSE, 1); // For testing curl_setopt ($c, CURLOPT_COOKIE, "PU='t=2'"); curl_setopt ($c, CURLOPT_COOKIE, "B='fjdqm0h38nja8&b=3&s=en'"); curl_setopt ($c, CURLOPT_COOKIE, "G='v=7&data=aV_mWZSWJqXQjMVAffABJZF90G5YVfEqEKS_8sCOGC3UJKe0r0CgoZ9Ys5lC44k1cNbU1Es8YvlWBV8HeBernGvtIA-WSq4kLkSKiwcQMo-uYLWwGFoQogK4oDv-rdb1JieLv7LLxUJvjCmZu8wAfBp8WO9dBI4gkypKEQK88Tcgb47bGiHVRZssV0LYodF64CAmb78Cu3I51FOXw1iZbUE76-qwQo2nz_qm-z21RwG8Tnm9yMed8ge588576Tqtxf7ebc3v06bvVYknMxT3AuuLpzSXb3MbyBxWXousng1nkcdooFGrFlVfSwcbl2scqfr8hBOoJLeoPdY6_aLrEtZghtVg1tvwclO3fSvXVa7TBhhHHzJ1JrD7_q-8mN140EjYon9Z4ump3lh6NHerJHlKE63J0t-syUMDNo3muAzYFQulYjQ&n=8'"); curl_exec ($c); The page outputs:- "Aren't you supposed to be somewhere else?" I'm guessing that perhaps the cookies aren't being set properly. Any pointers / articles / sites? Can I use a cookies.txt file from a valid visit to the site to set this up?
Use curl_setopt() to let curl save the cookies. Specifically you need these two options: CURLOPT_COOKIEFILE CURLOPT_COOKIEJAR http://us2.php.net/manual/en/function.curl-setopt.php Also, you might want to think about passing it a different User-Agent then the default curl agent
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie.txt'); // Make sure location is writable curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt'); // Make sure location is writable -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare

« previous php.general (#258421) next »