cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problem when retrieving cookies by using curl_easy_getinfo()

From: Robert Alm <still_at_telia.com>
Date: Wed, 15 Oct 2008 18:34:41 +0200

Hi. I'm trying to retrieve a cookie from cURL after a request. More
specifically I need the
PHP session ID. I'm using the following code:

 

 

  curl_global_init( CURL_GLOBAL_ALL );

  m_hCurl = curl_easy_init();

 

  curl_easy_reset( m_hCurl );

  curl_easy_setopt( m_hCurl, CURLOPT_URL, "http://localhost/page.php" );

  curl_easy_setopt( m_hCurl, CURLOPT_WRITEFUNCTION, curlWriterFunc );

  curl_easy_setopt( m_hCurl, CURLOPT_WRITEDATA, this );

  curl_easy_setopt( m_hCurl, CURLOPT_COOKIEFILE, ""); // Just start the
cookie engine.

  curl_easy_setopt( m_hCurl, CURLOPT_VERBOSE, 1 );

  curl_easy_setopt( m_hCurl, CURLOPT_DEBUGFUNCTION, curlDebugFunc );

  curl_easy_setopt( m_hCurl, CURLOPT_DEBUGDATA, this );

  curl_easy_setopt( m_hCurl, CURLOPT_COOKIESESSION, 1 );

 

  curl_easy_perform(m_hCurl);

 

The page.php file being requested only contains a simple session_start()
call, which
then gives me my session cookie.

I print all cookies with the following code:

 

  curl_slist* pCookies = 0;

  curl_slist* p = 0;

  curl_easy_getinfo( m_hCurl, CURLINFO_COOKIELIST, &pCookies );

  p = pCookies;

  while( p )

  {

      TRACE( p->data );

      p = p->next;

  }

 

  curl_slist_free_all(pCookies);

 

The output I get is one single cookie which is printed:

 

"localhost FALSE / FALSE 0 PHPSESSID
b85trrss63s8pl2oovgg3mon13"

 

This doesn't look good to me. What I was hoping for is a nice
string specifyin only "PHPSESSID" and "b85trrss63s8pl2oovgg3mon13" which is
the
session ID cookie.

 

What am I doing wrong?

 

Regards
Robert
Received on 2008-10-15