I have a php script that is being used login into a remote site and it is working well. However it seems to only works when the designated cookie file is named cookie.txt
What I want is for each person who uses this script to have a separate cookie file. So if a person on machineA uses it on the 19th they’re cookie will be located in something like /tmp/19/someNameCookie.txt, machineB would have /tmp/19/someOtherNamedCookie.txt, and if machineC uses it on the 20th they will have /tmp/20/someNamedCookie.txt.
There are many ways to generate uniquely named files but the key here is getting them to work. I’ve very young in the php knowledge and completely new to curl.
On a side note, I’ve also have had no success using CURLOPT_FOLLOWLOCATION for getting the new page that results from logging in.
Thanks.
Here’s a code exert. Got to this from another source.
$username=urlencode($usr);
$password=urlencode($pass);
$url="http://domain.com/";
$cookie="cookie.txt";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie); // have tried with just the jar, and just the file and both
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
echo $result;
curl_close($ch);
And this is the code I would call after to check if the login is successful
$ch2 = curl_init();
//curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch2, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch2, CURLOPT_URL, "http://domain.com/");
$r = curl_exec($ch2);
echo $r;
curl_close($ch2);
From my understanding curl is supposed to create the cookie file if it doesn’t exist. I’ve also tried creating other files manually and through script using fopen but still only works if I’m using cookie.txt, and right now it’s all being saved to public_html just for testing.
set the
Cookie Jar