简体   繁体   中英

Back to last page viewed on multi page site

Please forgive me if I'm over complicating this.

My goal: build an online course which allows the user to return to where they last stopped on a multi-page html/php site.

I purchased the aMember script, it's a php script that protects folders and files and allows membership levels. It does not come with any pre-made course pages or such, just a server side protection. It allows registration of user accounts and gives them access to specific folders and pages.

==== What I want to do is to build a sequential html5 course, with smaller chunks of info in each for easier learning. Building a menu to jump around is not ideal for this type of course. So I would want a button that takes a logged in user back to the page where they visited last time and to include it in the DB so that they can log in from anywhere and not count on cookies.

I am not a programmer so it's hard for me to explain in shorter terms, I hope you can understand and direct me to the right resources. Thanks!

Create a script that's included in every page of your site which will send info about user id,last visited page,time etc to database and your login script will redirect user accordingly from the information in your DB. Should not be that hard, if you need any code examples then ask.

You should store maybe user id in a session in login script. For example the script for saving should be something like this:

if(isset($_SESSION['u_id'])){
  $db_handler=mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die 
  ('ERROR: Could not connect.');
  $u_id = $_SESSION['u_id'];
  $ref = $_SERVER['HTTP_REFERER'];
  $query= "INSERT INTO user_activity(u_id,page) VALUES ($u_id, $ref);";
  $res = mysqli_query($db_handler,$query);
  if(!$res) {
    die("ERROR: " . mysqli_error($db_handler));
  }
}

And in your login script you should have something like this:

if(isset($_POST['user'])){
  $db_handler=mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die 
  ('ERROR: Could not connect.');
  $u_id = $_POST['user'];
  $query= "SELECT t.id,u.u_id,u.page from users t JOIN users_activity u ON t.id=u.u_id WHERE u.u_id=$u_id;";
  $res = mysqli_query($db_handler,$query);
  if(!$res) {
    die("ERROR: " . mysqli_error($db_handler));
  }
}    

Should give you some idea, got busy at work so can't do better right now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM