I am currently using localstorage to store what pages the current user has visited:
<?php
//start the session
session_start();
//set $username as the current logged in user
$username=$_SESSION["Username"];
?>
JQuery:
var journey = JSON.parse(localStorage.getItem('journey'))||[];
journey.push(location.protocol +
'//' + location.host + location.pathname);
localStorage.setItem('journey', JSON.stringify(journey));
Currently this is a temporary storage, however I would also want to give them the option to save their journey.
How would I be able to save the individual URL’s along with the user’s ID (which is already stored in the database) into the MySQL database? e.g. table name ‘Journey’ with columns ‘URL’ and ‘UserID’.
The MySQL journey table:
The insert journey Query:
The update journey query if one already exists:
Your php script would echo a result at the end where the result is a boolean. True means save was sucessful, False means saving was a failure:
You would have a php script that executes these queries based on whether or not there is a record in the table referencing the user already.
An jQuery AJAX function like so would call the script and save the journey: