2

My cURL session is generating a new cookie everytime I run it. How can I use the same cookie for different scripts?

My settings:

curl_setopt($curl, CURLOPT_COOKIESESSION, false);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefilename);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefilename); 

Thanks!

3
  • What is $cookiefilename? Is it writable? Does the file exist and contain the expected data? Commented Apr 22, 2012 at 19:54
  • curl will honor the remote site's cookie settings. if the site's specified a 'session' lifetime on the cookie, curl will delete the cookie when the curl object is killed, regardless of the cookiefile/jar settings. Commented Apr 22, 2012 at 19:57
  • #lonesomeday, $cookiefilename is the file name's string. it is writable. Commented Apr 22, 2012 at 20:06

1 Answer 1

1

Have you tried using True?
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
Have you verified that cookies are being written to $cookiefilename?
Are you trying to 're-run' the script within the duration of the cookie(s)?

You are trying to re-use the cookie(s)?

Sign up to request clarification or add additional context in comments.

2 Comments

I have several access steps I am doing on my cURL. IF I set that to True, on any of them, all the session is ruined and I can't get to the point I need. -the cookie is written ok to file. About the duration, I am not sure how to tell all it says is: #HttpOnly_www.server.com FALSE / FALSE 0 ASP.NET_SessionId 5g5iq0yozfe3pw20mpa5dz45
Do you call ALL the curlopt's for each step? I have a script that logs in on the first pass and stores them in COOKIEJAR. On subsequent executions of the script the file is opened for reuse by COOKIEFILE. In short, the cookies are still valid for awhile and allow the script to bypass the login steps. The script only sets the 3 curlopts you show in question ONCE before the initial curl_exec($curl)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.