Victor Kimura
asked on
curl php - error:your browser is not accepting cookies
Hi,
I receive an error in the $file when I try the curl. It's basically saying that my browser's cookie is not enabled which it is.
When I login in manually I can see that 'id' and the 'pass'. What I'm trying to do is login and then grab the 'id' and 'pass' in the resulting page.
Any ideas?
I receive an error in the $file when I try the curl. It's basically saying that my browser's cookie is not enabled which it is.
When I login in manually I can see that 'id' and the 'pass'. What I'm trying to do is login and then grab the 'id' and 'pass' in the resulting page.
Any ideas?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginurl);
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$file = time().'.txt'; // view the page for debugging
$fh = fopen($file,'w');
fwrite($fh,$result);
fclose($fh);
$info = curl_getinfo($ch);
$curlError = curl_error($ch);
preg_match('/id=(.*)?&pass=(.*)?">/', $result, $links);
$id = $links[1];
$pass = $links[2];
ASKER
Hi marchent,
How do I provide my apache to write the cookie file?
I changed the cookie.txt to an absolute path. I changed the cookie.txt file to 777 just to see if that would work. I still receive the same error.
The page is here:
http://discountnwa.com/curl/ezine_login2.php
I'm really baffled as I know this should work.
Thanks for your help,
vkimura
How do I provide my apache to write the cookie file?
I changed the cookie.txt to an absolute path. I changed the cookie.txt file to 777 just to see if that would work. I still receive the same error.
The page is here:
http://discountnwa.com/curl/ezine_login2.php
I'm really baffled as I know this should work.
Thanks for your help,
vkimura
ASKER
Just another note on the cookie.
If you execute
the PHPSESSID=m596pavpktd68jhq dkq60vhjs5 ;
http://discountnwa.com/curl/ezine_login2.php
When I look at the cookie.txt file it contains the same PHPSESSID. So it looks like the cookie is saved but for some reason it's not being read.
If you execute
the PHPSESSID=m596pavpktd68jhq
http://discountnwa.com/curl/ezine_login2.php
When I look at the cookie.txt file it contains the same PHPSESSID. So it looks like the cookie is saved but for some reason it's not being read.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, marchent. That worked
Also, change the ownership of the cookie file. Just provide your apache to write the cookie file.