Hi,
When you go to load the page for the first time, can you not check the session for the current page:
$currentPage = isset($_SESSION['current_page']) ? $_SESSION['current_page'] : 'default_page_template';
If the session is set, then load the current page, otherwise, revert to your default page. Then when the link on your default page is clicked, I assume you're making an ajax request to the server. At this point, on the server side, set the current_page session variable to the page you're returning.
R.
blocblue
Practically a Posting Shark
837 posts since Jan 2008
Reputation Points: 272
Solved Threads: 161
Skill Endorsements: 12
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.
blocblue
Practically a Posting Shark
837 posts since Jan 2008
Reputation Points: 272
Solved Threads: 161
Skill Endorsements: 12