no javascript for me thank you... i don't think thats reliable enough...
i don't like cookies as they are editable by the user and so could fake what their last page was
i think ill stick with the session...
something like this im working on
this is just for concept at the moment, not sure how i will use it in any sort of real life situation though...
thinking of using serialize() for the session...
<?php
define( 'SITEVISIT_WITH_QUERY', 1 );
define( 'SITEVISIT_WITHOUT_QUERY', 0 );
class SiteVisit
{
var $page_list;
var $session_name;
function SiteVisit()
{
$this->session_name = 'site_visit';
$this->getFromSession();
}
function getFromSession()
{
if( !isset($_SESSION[$this->session_name]) ) {
$_SESSION[$this->session_name] = array();
}
$this->page_list =& $_SESSION[$this->session_name];
}
function logThisPage( $with_query_string=SITEVISIT_WITHOUT_QUERY )
{
$this_page = $_SERVER['PHP_SELF'];
if ( $with_query_string==TRUE ) {
$this_page .= "?{$_SERVER['QUERY_STRING']}";
}
$this->logPage($this_page);
}
function logPage( $uri )
{
array_unshift( $this->page_list, $uri );
}
function lastPage()
{
return $this->previousPage( 1 );
}
function previousPage( $how_far=1 )
{
return $this->page_list[$how_far];
}
function hasBeenTo( $uri )
{
return in_array($uri,$this->page_list);
}
function clear( $how_many=NULL )
{
if ( $how_many = NULL ) {
$this->page_list = array();
} else {
for ( $i=0; $i<$how_many; $i++ ) {
array_pop( $this->page_list );
}
}
}
}
header("Content-type:text/plain");
$sv = new SiteVisit();
print_r($sv->page_list);
$sv->logThisPage(SITEVISIT_WITH_QUERY);
print_r($sv->page_list);
/// $sv->clear();
?>