<p>I'm writing a C++ client which is using libcurl for communicating with a PHP script.</p>

<p>The communication should be session based, and thus the first task is to login and make the PHP script set up a session.</p>

<p>I'm not used to working with sessions either from C++ or PHP. I basically know that it has to do with cookies and communicating session id.</p>

<p>I can't find any example on the curl homepage which demonstrates a simple session management use case.</p>

<p>I'm assuming it has something to do with one or many of the following options in curl:</p>

<pre><code>CURLOPT_COOKIE
CURLOPT_COOKIEFILE
CURLOPT_COOKIEJAR
CURLOPT_COOKIESESSION
CURLOPT_COOKIELIST
</code></pre>

<p>But I can't really see the big picture just from the documentation of CURLOPT_COOKIESESSION for instance.</p>

<p>Anybody who has done this, please share a simple piece of code which shows the concept.</p>

<p>Regards</p>

<p>Robert</p>

A session in PHP has the purpose of preserving some state over several requests, since HTTP in itself is stateless. To get a session from PHP, simply request a php page that starts a session, and keep the cookie you get back for subsequent requests.
Starting a session in php is simple - call the session_start() function. That function will resume an existsing session if the cookie exists in the request. When the session is started, persistent variables can be set using the superglobal array $_SESSION. It's a good idea to store a 'is logged in'-token there =) To end the PHP session, set $_SESSION to array(), so that the token is destroyed.