Question: Is it possible to use something like sessions like the ones in PHP in C++?

In PHP they're used like

```
$_SESSION['name'] = $value;

```

I really want to make the same application using C++ as PHP...requires a run-time parser.

My application written in PHP uses sessions so that i can fetch some stuff from a website(numbers) and store the value in a SESSION varible which i call last to compare it to the new value when the page is reloaded.

I'd rather have the same functionality in C++.

Seeing as this is going nowhere i am going to provide the PHP code

```
<?php
session_start();

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://dashjr.org/~luke-jr/programs/bitcoin/pool/balances.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);

echo 'Last BTC: '.$_SESSION['last'].'<br>';

$obj = json_decode($result,true);
echo 'Current BTC: ';
$new = (int)$obj["1Hy5h24yBYKtQ1vNGaxY5rBJSEuTiMkBkx"]["balance"]/100000000;
echo $new;

if((int)$_SESSION['last'] < $new)
{
    echo '<br><br>You earned more';
}
else
{
    echo '<br><br>You earned less';
}

$_SESSION['last'] = $obj["1Hy5h24yBYKtQ1vNGaxY5rBJSEuTiMkBkx"]["balance"]/100000000;

unset($result,$obj);

?>

```

I need to port *that* to C++.

Answer: 
If your data requirements are small you could just store the value in a cookie which the caller will pass back to the C++ CGI program when it invokes it again.

EDIT: As this isn't a webapp, just use regular C++ IO functions to preserve the data, either in a file, a registry key (for Windows) or, if you've got extensive data requirements, an embedded database like Sqlite.

EDIT: If it's just sitting in a loop, and you don't need to preserve the value from one invocation to another (i.e. across program restarts), just store the value in a different variable. You can just use an [STL hashmap](http://www.cplusplus.com/reference/stl/map/) as the "SESSION" if you want to use name/value pairs. Or am I missing something fundamental?
> 
> PHP...requires a run-time parser.
> 
> 
> 

Nope, install apc or any other compiled code cache, and php is only parsed once. Of course the generated bytecode is still interpreted...

On big frameworks (lots of code) parsing time can be a lot longer than actual script execution, so this cuts down the page times quite a lot.