登录后如何将用户重定向到他们的特定 id 网址/登陆页面? [英] How to redirect the users to their id specific urls/landing pages after they log in?
问题描述
如何在用户登录后将用户重定向到他们的特定 id 网址/登陆页面?重定向 url 的查询字符串应显示与其存储在 Mysql 数据库中的 id(主键)相关联的值.
How to redirect the users to their id specific urls/landing pages after they log in? The redirected urls' query strings should show values associated with their ids (Primary key) stored in Mysql database.
例如
第1、第2、第3、第4个用户的id"对应的值为1、2、3&4
The corresponding values of "id" for 1st, 2nd 3rd and 4th users are 1, 2, 3 & 4
用户登录成功后,登录页面/登陆页面分别如下图所示.
The logged pages / landing pages should look like the following urls respectively after the users are looged in successfully.
www.anysite.com/anydirectory/user.php?id=1
www.anysite.com/anydirectory/user.php?id=1
www.anysite.com/anydirectory/user.php?id=2
www.anysite.com/anydirectory/user.php?id=2
www.anysite.com/anydirectory/user.php?id=3
www.anysite.com/anydirectory/user.php?id=3
www.anysite.com/anydirectory/user.php?id=4
www.anysite.com/anydirectory/user.php?id=4
*登录脚本的登录会话如下:*
*The log in session of the log in script is as following:*
//设置会话并登录用户**
// this sets session and logs user in**
session_start();
//防止会话固定攻击.
session_regenerate_id (true);
//在会话中设置变量
$_SESSION['user_id']= $id;
$_SESSION['user_name'] = $full_name;
$_SESSION['user_level'] = $user_level;
$_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
**//update the timestamp and key for cookie**
$stamp = time();
$ckey = GenKey();
mysql_query("update users set `ctime`='$stamp', `ckey` = '$ckey' where id='$id'") or die(mysql_error());
//设置cookie
if(isset($_POST['remember'])){
setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*COOKIE_TIME_OUT, "/");
setcookie("user_key", sha1($ckey), time()+60*60*24*COOKIE_TIME_OUT, "/");
setcookie("user_name",$_SESSION['user_name'], time()+60*60*24*COOKIE_TIME_OUT, "/");
}
header('Location: user.php');
}
}
else
{
//$msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
$err[] = "Invalid Username Or Password.";
我应该使用什么标头以这种方式重定向用户?此外,如何为相同目的创建登录页面.
What header I should use to redirect the users that way? Also, how to create the landing page for the same purpose.
任何帮助将不胜感激.
推荐答案
只需将 $_SESSION
中的用户 ID 附加到您要重定向到的 URL.
Just append the user id from your $_SESSION
to the URL you're redirecting to.
header('Location: user.php?id=' . $_SESSION['user_id']);
这篇关于登录后如何将用户重定向到他们的特定 id 网址/登陆页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!