0

Let's say I have a website called somewebsite.com and it has cookies, how would I get those cookies in my domain with cURL, I did try to do this with this method (from stackoverflow, but didn't seem to work)

/* STEP 1. let’s create a cookie file */
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
/* STEP 2. visit the homepage to set the cookie properly */
$ch = curl_init ("http://somedomain.com/");
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

/* STEP 3. visit cookiepage.php */
$ch = curl_init ("http://somedomain.com/cookiepage.php");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
Grigor
  • 4,139
  • 10
  • 41
  • 79
  • A website doesn't have cookies. A website can ask the clients that connect to set cookies in some way. I guess you could say a server "gives" clients cookies. Then, on successive page requests, the client references the cookie. In our analogy, the clients demonstrate that they were given cookies previously, and which kind. Basically with cURL you could (a) do whatever you need to do to have the server send you the cookie again (login, access a certain page, etc.) via your cURL session or (b) extract a cookie from your browser session and import it into your cURL cookie jar. – jedwards Jun 09 '12 at 05:35
  • I understand that, however that didn't solve my problem. – Grigor Jun 09 '12 at 05:42
  • 1
    tip: don't call curl_init each time. you can simply a new url with `curl_setopt(CURLOPT_URL, '...')` instead. Even without a cookiejar/cookiefile setting, curl will keep cookies going for the duration of the curl session. – Marc B Jun 09 '12 at 05:44
  • possible duplicate of: http://stackoverflow.com/questions/895786/how-to-get-the-cookies-from-a-php-curl-into-a-variable – yakxxx Jun 09 '12 at 10:04

0 Answers0