Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

curl php - error:your browser is not accepting cookies

Posted on 2009-04-14
5
Medium Priority
?
381 Views
Last Modified: 2012-05-06
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?
$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];

Open in new window

0
Comment
Question by:Victor Kimura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:marchent
ID: 24138941
use the cookie file with absolute path name. For example instead of using "cookie.txt", use "/tmp/bla/bla/bla/cookie.txt"

Also, change the ownership of the cookie file. Just provide your apache to write the cookie file.
0
 

Author Comment

by:Victor Kimura
ID: 24140713
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
0
 

Author Comment

by:Victor Kimura
ID: 24140759
Just another note on the cookie.

If you execute
the PHPSESSID=m596pavpktd68jhqdkq60vhjs5;
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.
0
 
LVL 13

Accepted Solution

by:
marchent earned 2000 total points
ID: 24141216
Sorry, I didn't notice your code correctly. When using cookie-jar, needs to add 2 lines like below. Just add the other one, which you didn't
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);

Open in new window

0
 

Author Closing Comment

by:Victor Kimura
ID: 31569797
Thanks, marchent. That worked
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question