Jump to content

Get a cookie value with cURL


Goose

Recommended Posts

I am working on a website that depends on a complex cookie being set. In an effort to fix problems before they become big problems, I want to monitor that the cookie is getting set correctly with a cron job. I can setup the cron job just fine, but I can't figure out how to get the value of the cookie.

 

By visiting the main site the cookie is set automatically, and I've also made a special script on that server that only gets me that cookie value and spits it out. I am trying to use cURL to call the main page, and then right after that, call the get-cookie.php page which should then have cookie data to display.

 

Here is how I am trying to do it now:

<?php

$c = curl_init();

// making the initial call to the real website
curl_setopt($c, CURLOPT_URL, 'http://domain.com');
curl_setopt($c, CURLOPT_HEADER, false);
curl_exec($c);

curl_close($c);

$c = curl_init();

// now making a call to the script that spits out the cookie
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_URL, 'http://domain.com/get-cookie.php');
curl_setopt($c, CURLOPT_HEADER, false);

$output = curl_exec($c);

curl_close($c);

echo 'output: ' . $output . "\n\n";

?>

 

I've tried a few different things here, but so far no luck. Anyone have any ideas on how I can make this work? Thanks so much!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.