Session variables are a PHP thing, not a shell one. Calling the setup you have "shell variables" is a bit of a misnomer, anyway. You don't have any shell sitting around holding these variables -- you have a file the values sit in. The shell exists only for a split second as it loads that file and feeds the values into PHP. That's
why you have to load it every time -- once the page finishes loading, whatever process was producing the output
quits and
no longer exists. I don't understand the point of involving the shell at all.
The shell isn't involved at all for PHP session variables. The entire point is to conveniently carry the same variables between different page loads. When the script ends, the contents of $_SESSION are saved somewhere. When the script begins, the contents of $_SESSION are loaded from somewhere. It gives a cookie to the client so it knows which browser has which values. It's sort of analogous to the system you have, but is a feature built into PHP that can tell between different clients and autoloads/autosaves for you.
These values are generally stored on the server itself. You can even control what directory it saves sessions inside by calling session_save_path before you call session_start().
My examples aren't going to be any better than the ones I linked, but if you really want them, here's one written from scratch. It should be a fairly self-contained thing which uses form POST's to tell it what variables to write into $_SESSION.
PHP Code:
<?php // this MUST happen before any other output is written!
// The session must start before HTTP headers are sent for
// cookie-based sessions to work.
session_start();
// Did we get a POST request with a value to add or update?
// Change the contents of $_SESSION as directed.
if(isset($_POST['key']))
{
printf("<!-- setting %s => %s -->\n", $_POST['key'], $_POST['value']);
$_SESSION[$_POST['key']]=$_POST['value'];
}
?>
<body><html>
<table border=1>
<tr><th colspan=2>Your session ID is <?php echo session_id(); ?></th></tr>
<tr><th>Key</th><th>Value</th></tr>
<?php $N=0;
foreach($_SESSION as $k => $v)
{
$N++; ?>
<tr><td><?php echo $k ?></td><td><?php echo $v ?></tr>
<?php } ?>
<tr><td colspan='2'><?php echo $N; ?> keys</td></tr>
<form method='post'>
<tr>
<!-- Textboxes to input values -->
<td><input type='text' name='key'></td>
<td><input type='text' name='value'></td>
</tr>
<!-- Submit button -->
<tr><td colspan='2'><input type='submit'></td></tr>
</form>
</table>
</html></body>