如果用户名与我的cookie令牌匹配,则重定向用户PHP / MySQL的

时间:2013-05-27 14:23:51

标签: php session cookies

我曾经使用过未加密的Cookie,因此以下代码运行良好:

$username = $_REQUEST['username'];
if ( $username == $_SESSION['loggedin'] ) { 
echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL='/profile.html'\">";
} else {

但是现在我的cookie工作在MySQL加密的cookie令牌基础上。我需要基本检测您尝试访问的用户名/配置文件是否与您的cookie令牌匹配的用户名/配置文件相同,然后将您重定向到/profile.html。我不太清楚怎么做?有什么建议或帮助吗?我看过网上但似乎无法找到解决方案。

2 个答案:

答案 0 :(得分:0)

你可以试试这个:

$username = $_REQUEST['username'];
if ( $username == $_SESSION['loggedin'] ) { 
  header('Location: /profile.html');

...

答案 1 :(得分:0)

$username = $_REQUEST['username'];
if ( $username == $_SESSION['loggedin'] ) { 
header("Location: /profile.html");
}

并且不要忘记使用此函数启动会话:session_start();