简体   繁体   English

返回上一页在多页站点上查看的页面

[英]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. 我的目标:建立一个在线课程,允许用户返回到他们在多页html / php网站上最后一次停止的位置。

I purchased the aMember script, it's a php script that protects folders and files and allows membership levels. 我购买了aMember脚本,它是一个PHP脚本,用于保护文件夹和文件并允许会员级别。 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. ====我想做的是建立一个顺序的html5课程,每个课程都有较小的信息块,以便于学习。 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. 因此,我希望有一个按钮将登录的用户带回他们上次访问的页面,并将其包含在数据库中,以便他们可以从任何地方登录而不必依靠cookie。

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. 创建一个包含在您网站的每个页面中的脚本,该脚本会将有关用户ID,上次访问的页面,时间等信息发送到数据库,并且您的登录脚本将从数据库中的信息中相应地重定向用户。 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. 您应该在登录脚本的会话中存储用户ID。 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. 应该给您一些想法,忙于工作,所以现在不能做得更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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