我目前上传了一个简单的php登录脚本,这是在这里提供的
此登录包附带1个sql文件和简单的PHP代码,一旦登录就会将用户带到logged_in.php,否则它将保留在not_logged_in.php(非常基本)。
它还带有一个功能正常的注册页面(非常简单)。
我需要编辑哪个页面,以及我将使用哪些代码进行编辑,以便user1为user2获取不同的目标网页。
非常感谢。
编辑:
// ... ask if we are logged in here:
if ($login->isUserLoggedIn() == true) {
// the user is logged in. you can do whatever you want here.
// for demonstration purposes, we simply show the "you are logged in" view.
include("views/logged_in.php");
} else {
// the user is not logged in. you can do whatever you want here.
// for demonstration purposes, we simply show the "you are not logged in" view.
include("views/not_logged_in.php");
我希望将user1的登录页面输入sql表并获取它,以便在该用户登录后转到该链接。
答案 0 :(得分:0)
根据您的简单脚本,有几种方法可以做到这一点。
1)更改logged_in.php以检查登录的用户,并根据某些地图将其转发到个性化登录页面,或者您计划处理该用户。
2)更改log_in函数以返回用户应转发到的页面而不是布尔值(在此处做出假设)。然后,接收页面将根据用户是否成功放入来转发用户。
3)更改log_in功能,将用户转发到该用户的相应页面,无论是登录页面还是失败页面。
在你的情况下,我可能会选择#3 ,因为它是最直接的实现。
答案 1 :(得分:0)
在您对用户进行身份验证的登录脚本页面中,您可以在进行身份验证后将user1带到与user2不同的登录页面。一种方法是将用户的页面名称存储在sql本身的身份验证之后,并在登录时检索它。然后在header('location:<mysql_value')
中使用它。但这将为用户创建每个页面。这非常多余。
这里
// ... ask if we are logged in here:
if ($login->isUserLoggedIn() == true) {
$page = "SELECT page_name from users WHERE userid='$loggedin_userid'";
$query = mysql_query($page);
$page_name = mysql_result($query,0);
if($page_name){ header("location:'$page_name'"); //or include($page_name);}
} else {
// the user is not logged in. you can do whatever you want here.
// for demonstration purposes, we simply show the "you are not logged in" view.
include("views/not_logged_in.php");
}
但仍然存在问题。您必须为每个用户物理创建页面。
我的代码:
// include the configs / constants for the database connection
require_once("config/db.php");
// load the login class
require_once("classes/Login.php");
// create a login object. when this object is created, it will do all login/logout stuff automatically
// so this single line handles the entire login process. in consequence, you can simply ...
$login = new Login();
// ... ask if we are logged in here:
if ($login->isUserLoggedIn() == true) {
$page = "SELECT landing_page from users WHERE userid='$user_id'";
$query = mysql_query($page);
$landing_page = mysql_result($query,0);
if($landing_page){ header("location:$landing_page"); }
} else {
// the user is not logged in. you can do whatever you want here.
// for demonstration purposes, we simply show the "you are not logged in" view.
include("views/not_logged_in.php");
}