1

I have below curl code to GET.

<?php  
function get_content($URL){
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
          curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
          curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); 
          curl_setopt($ch, CURLOPT_URL, $URL);
          $data = curl_exec($ch);
          curl_close($ch);
          return $data;
      }
 echo get_content("http://www.domain.com/cool.php");
?>

I have used http headers and cookie looks like below

xidseq:22
xid:b05f251c-8a72-4c2b-a230-e03b9c5c87b7&&BAYIDSAMFE1C013&343
data:dsfsfssdss

I need to send GET request to http://www.domain.com/cool.php with some cookies.

how do i put the cookie in cookie.txt ?? is there any specific format for cookies..or just posting it works ?

7
  • the cookie file should look like the old netscape-style cookies.txt Commented Oct 23, 2012 at 19:21
  • dupe: stackoverflow.com/questions/12752555/sessions-with-curl and stackoverflow.com/questions/13020404/… <- has code example, gimme an up vote on one of those :) Commented Oct 23, 2012 at 19:23
  • its irrelevant to my question Commented Oct 23, 2012 at 19:24
  • I was wrong with my previous comment -- you will most likely want both. Here is the best documentation I could find at the time. Commented Oct 23, 2012 at 19:27
  • I understand now. Thing Marc B. was on right track then. See RFC2965 Commented Oct 23, 2012 at 19:27

1 Answer 1

1

If script above doesn't work try:

curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt'); 
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt'); /* make sure you provide FULL PATH to cookie files*/

Check file permissions and ownership on dirname(__FILE__) . '/cookie.txt' . Make sure file is writable.

To put the cookie in cookie.txt you need to visit certain web page that contains them - only server side cookies you can fetch with cURL, javascript cookies is not reachable vie cURL, at least not directly.

If you want to create cookies manually for your GET request, read about Netscape cookies format or - best way, save some 'real website' cookies via CURLOPT_COOKIEJAR to see and understand format.

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

Comments

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.