goldensona — 2012-07-21T02:00:40-04:00 — #1
i have login via curl ,after successful login i couldnt get home page content via curl once successful login ,it again said to login. how to maintain session and cookie when calling a api via curl. can anyone give a solution .
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); // The name of a file to save all internal cookies to when the connection closes
curl_setopt($ch, CURLOPT_HEADER,0); // TRUE to include the header in the output.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $result = curl_exec($ch); //execute curl and store data in result
tamilsuresh — 2012-07-21T11:32:37-04:00 — #2
Try Follow Location as 1, this might fix your problem
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // it will follow with server redirects
goldensona — 2012-07-24T01:44:49-04:00 — #3
if i login via one browser it was working fine, if i login via some other brower means it take cookie previously stored in the text and logged with the same user. how to avoid.
how do to do like separate cookie for each browser. if we login one account via firefox in gmail ,we may login in gmail with another account in chorme or some other browsers. i want to do like that with curl . how to manage cookie and session when calling a url with curl