This might work, but you'd need a database and table...
home.php:
<?php
Function check_visit()
{
$host = "localhost";
$user = "root";
$pass = "";
$database = "my_website_db";
$table_name = "access_list";
$ipaddress = getenv('REMOTE_ADDR');
// Get this IP Address of that person
$conn = mysql_connect($host,$user,$pass);
// Connect to MySQL
$db = mysql_select_db($database);
// Select your Database
$mysql_query = 'SELECT "visited_pages" FROM "'.$table_name.'" WHERE "ipaddress"=\''.$ipaddress.'\' LIMIT 1';
// Create your MySQL Code
if(mysql_num_rows(mysql_query($mysql_query)) < "1") {
mysql_query("INSERT INTO \"$table_name\" VALUES('0','$ipaddress','')");
$executed = mysql_query($mysql_query);
// if user isn't registered, it registers the user and then executes the query...
}else{
$executed = mysql_query($mysql_query); }
$user_details = mysql_fetch_array($executed);
// Get the user details array
$visited_arr = explode("--=|=--",$user_details['visited_pages']);
// get the list of pages this person has visited
$a = count($visited_arr);
for($x=0;$x<$a;$x++){
if($visited_arr[$x] == $_SERVER['SCRIPT_NAME']){
$found = "yes";
}
if($visited_arr[$x] != null){
$visited .= $visited_arr[$x]."--=|=--"; }
}
if($found != "yes"){
$visited .= $_SERVER['SCRIPT_NAME'];
$code = 'UPDATE "'.$table_name.'"
SET "visited_pages" = \''.$visited.'\'
WHERE 1 AND
"ipaddress"=\''.$ipaddress.'\'';
mysql_query($code); }
// if it the person hasn't viewed this page before, it updates the table
mysql_close($conn);
}
Function get_pages()
{
$host = "localhost";
$user = "root";
$pass = "";
$database = "my_website_db";
$table_name = "access_list";
$ipaddress = getenv('REMOTE_ADDR');
// Get this IP Address of that person
$conn = mysql_connect($host,$user,$pass);
// Connect to MySQL
$db = mysql_select_db($database);
// Select your Database
$sql = 'SELECT * FROM "'.$table_name.'" WHERE "ipaddress"=\''.$ipaddress.'\'';
// make the query again
$qry = mysql_query($sql);
// execute the query again
$c_row = mysql_fetch_array($qry);
// fetch the result set
$v_list = explode("--=|=--",$c_row['visited_pages']);
// get the new updated list of visited pages
$j = count($v_list);
// Count how many pages the person has visited
for($i=0;$i<$j;$i++){
if($i < 1){ $page = "<b>Since you have first visited you have viewed: </b>".$j." <b>Pages<br><br>The very first page you have visited is: </b>".$v_list[$i]."<br>"; }
else{ $page .= "<b>You have also visited: </b>".$v_list[$i]."<br>"; }
}
mysql_close($conn);
return $page;
}
check_visit();
// must use this on ALL your pages... this checks and UPDATES the visited pages list
echo(get_pages());
// use this if you want to tell people the pages they have visited WARNING: shows the complete url to each page....
?>
I have tested this code on my comp and it works fine...
There are 2(TWO) functions..
check_visit() = checks and updates visited pages list
get_pages() = returns a list of pages the user has visited
use at will 😉