Well you said you were using ajax, and you are therefore making requests to the server. The PHP to which you're directing requests is obviously responding with the page content that is loaded in your div. Therefore, as stated above, why do you not set the SESSION variable within the PHP script that is responding to your asynchronous requests?
I've thrown together a crude example below. When you first load page.php, the div, etc, will be outputted. If the default page content contained something like:
<p>This is another page <a class="page" href="/example" title="Example page">Example page</a></p>
<?php
// page.php script
session_start();
// Check whether specific page requested, otherwise check for currently loaded page, else display default page
// Make sure you validate all incoming variables
$page = isset($_POST['page']) ? $_POST['page'] : (isset($_SESSION['page']) ? $_SESSION['page'] : 'default');
$isAjax = isset($_POST['ajax']) ? (bool)$_POST['ajax'] : false;
// Output content container if request isn't ascynchronous
if(!$isAjax) : ?>
<div id="contentContainer">
<?php endif;
// Output correct content based on $page. E.g:
echo file_get_content($page);
// Output content container if request isn't ascynchronous
if(!$isAjax) : ?>
</div>
<?php endif;
$(function() {
$('a.page').live('click', function(event){
event.preventDefault();
var href = $(this).attr('href');
$.ajax({
url: 'page.php',
data: 'ajax=1&page=' + href,
success: function(data) {
$('div#contentContainer').html(data);
}
});
});
});
Does this help to clarify my thought process?
R.