I use these scripts on all of my sites and right now the script placement is limited to the right or left columns. Feel free to edit the output script but you need to be very familiar with how quoting works because this requires some javascript magic to work right.
It has to be done via javascript because of the page caching (otherwise your users would see only the history of the first user to cache the page).
It requires a php file custom box, a raw html custom box, as well as an inclusion of a css script or additions to the one you may already be calling.
Upload the following 2 scrpits to your AOM store root (above the AOM directory).
historysetvars.php
Code: Select all
<?
//--------------------------------------------------
$theuri = @$_SERVER['REQUEST_URI'];
$thehost = @$_SERVER['HTTP_HOST'];
$theurl = ("http://$thehost$theuri");
echo '<script type="text/javascript">';
echo "var name='".addslashes($page["Name"])."';";
if (isset($page["n"])){
echo "var n='".addslashes($page["n"])."';";
} else {
echo "var n='';";
}
if (isset($page["i"])){
echo "var i='".addslashes($page["i"])."';";
} else {
echo "var i='';";
}
if (isset($page["i"])){
echo "var asin='".addslashes($page["i"])."';";
} else {
echo "var asin='';";
}
if (isset($theurl)){
echo "var u='".addslashes($theurl)."';";
} else {
echo "var u='';";
}
if (isset($page["c"])){
echo "var c='".addslashes($page["c"])."';";
} else {
echo "var c='';";
}
if (isset($page["x"])){
echo "var x='".addslashes($page["x"])."';";
} else {
echo "var x='';";
}
echo '</script>';
?>
Code: Select all
<?
//start the session
session_start();
//register the history array
session_register('history');
//not used yet $alignment = 'VERTICAL';
//How many in the list
$listCount = '5'; //change this to alter the number of history items to show
//not used yet $hCols = '4';
//not used yet $vCols = '1';
//not used yet $categoryClass="aom_stn";
//not used yet $nameClass="aom_stn";
//class to use for display
$urlClass="aom_stn";
$ulClass="aom_stn";
//products in this category
//all products
//set the history var to the current session var
$theuri = @$_SERVER['REQUEST_URI'];
$thehost = @$_SERVER['HTTP_HOST'];
$theurl = ("http://$thehost$theuri");
$history = $_SESSION['history'];
//first see if we are on an item page
$i = @$_GET['i'];
$c = @$_GET['c'];
$name = @$_GET['name'];
$u = @$_GET['u'];
if (isset($i)) {
//is there any thing in the history yet
if (isset($history) ) {
//how many in the list now
$count = count($history);
//set the duplicate flag to zero
$inList=0;
foreach ($history as $v) {
//see if the asin is already in the list
if ($v["asin"]==$i) {
//it is in the list so do not add
$inList=1;
};
}
//if it is not in the list then add it
if ($inList == 0){
//if the current list is as big as $listCount remove the oldest one
if ($count >= $listCount) {
array_shift($history);
}
//add the new page to the list
$history[$count+1] = array( "category" => $c,"asin" => $i, "name" => $name, "url"=>$u);
$_SESSION['history'] = $history;
session_write_close();
}
} else {
//nothing in the history so add the first item
$history = array (array( "category" => $c,"asin" => $i, "name" => $name, "url"=>$u) );
$_SESSION['history'] = $history;
session_write_close();
}
}
//--------------------------------------------------
if (isset($history) ) { // display the history
echo "document.write('<ul class=history>');";
foreach ($history as $v) {
echo "document.write('".'<li><a href="'.$v["url"].'"><span class="'.$urlClass.'">'.addslashes($v["name"])."</a></span></li>');";
}
echo "document.write('</ul>');";
}
?>
put /path-to-your-root/historysetvars.php as the box content (replace 'path-to-yor-root' with the FILESYSTEM not web path, i.e. /public_html/mysite/historysetvars.php
Next, make another custom box. Make the box type 'Raw HTML', set the position to 'R' or 'L' only (because I have formatted the script for the right or left columns at this point) then add the following into the box contents:
THERE IS AN EDIT IN THIS SCRIPT YOU MUST DO! Change 'yoursitename.com' to, well, your site name.
Code: Select all
<script type="text/javascript"><!--
var qry='http://www.yoursitename.com/historyshow.php?c='+c+'&i='+asin+'&u='+escape(u)+'&name='+escape(name);
var jsstart='<scr'+'ipt type="text/javascript" src="';
var jsend='">';
document.write(jsstart+qry+jsend);
document.write('</scr'+'ipt>');
//-->
</script>
Code: Select all
ul.history {margin-left: 0.5em; padding-left: 0.5em;}
Code: Select all
<STYLE>
ul.history {margin-left: 0.5em; padding-left: 0.5em;}
</STYLE>
<script type="text/javascript"><!--
var qry='http://www.yoursitename.com/historyshow.php?c='+c+'&i='+asin+'&u='+escape(u)+'&name='+escape(name);
var jsstart='<scr'+'ipt type="text/javascript" src="';
var jsend='">';
document.write(jsstart+qry+jsend);
document.write('</scr'+'ipt>');
//-->
</script>
I hope you find the script useful, let me know if you have issues with it. It has been tested under PHP 5 and Apache 2, and I know it works with IE 6 up and Mozilla.