2016-02-06 223 views
0

我有PHP项目,用户可以在其中忘记时登录并申请新密码。我也有init.php它指导用户在用新密码登录后更改密码页面。强制用户在请求新密码后更改密码

INIT.PHP的代码将用户重定向如下:

$current_file = explode('/', $_SERVER['SCRIPT_NAME']); 
$current_file = end($current_file); 

if (logged_in() === true) { 

    if (user_active($user_data['username']) === false) { 
     session_destroy(); 
     header('Location: index.php'); 
     exit(); 
    } 

    if ($current_file !== 'user.php?p=change_password' && $user_data['password_recover'] == 1) { 
     header('Location: user.php?p=change_password&force'); 
     exit(); 
    } 

} 

$current_file只给我user.php,这是远远不够的,当然。我也试过$_SERVER['REQUEST_URI']这给我/user.php?p=change_password这很好。但仍然不起作用。我得到错误说The page isn't redirecting properly

所以总结一下。如果用户请求新密码,我需要将用户重定向到user.php?p=change_password&force

在此先感谢

+0

它全部在数据库中完成。一旦他们请求新密码,就会有一个值从0变为1 – Vurkac

回答

0

你可能会卡在重定向循环。这是我想发生:

  1. 你设法将用户重定向到user.php?p=change_password&force
  2. 一旦你这个网页上,包含$current_file !== 'user.php?p=change_password' if语句仍然是正确的
  3. 因此,你要重定向用户是相同的S页/他已经是上,造成一个重定向错误
0
$current_url = explode('/', $_SERVER['REQUEST_URI']); 
$current_url = end($current_url); 

if (logged_in() === true) { 

    if (user_active($user_data['username']) === false) { 
     session_destroy(); 
     header('Location: index.php'); 
     exit(); 
    } 

    if ($current_url !== 'user.php?p=change_password' && $user_data['password_recover'] == 1) { 
     header('Location: user.php?p=change_password'); 
     exit(); 
    } 

} 

此解决方案工作