[英]Force user to change password after requesting new password
I have PHP
project where users can login and request new password if they forget. 我有一个
PHP
项目,用户可以在忘记密码的情况下登录并请求新密码。 I also have init.php
where it directs the user to change password page after logging in with new password. 我还拥有
init.php
,它在此引导用户使用新密码登录后更改密码页面。
The code in INIT.PHP
to redirect the user is as follows: 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
is giving me user.php
only and this is not enough of course. $current_file
仅给我user.php
,这当然是不够的。 I have also tried $_SERVER['REQUEST_URI']
which gives me /user.php?p=change_password
which is fine. 我还尝试了
$_SERVER['REQUEST_URI']
,它给了我/user.php?p=change_password
很好。 But still does not work. 但是仍然不起作用。 I get errors saying
The page isn't redirecting properly
我收到错误消息,指出
The page isn't redirecting properly
So to sum up. 综上所述。 I need to redirect the user to
user.php?p=change_password&force
if they have requested a new password. 如果他们已请求新密码,则需要将用户重定向到
user.php?p=change_password&force
。
Thanks in advance 提前致谢
You might be stuck in a redirect loop. 您可能会陷入重定向循环。 Here's what I think happens:
我认为会发生以下情况:
user.php?p=change_password&force
user.php?p=change_password&force
$current_file !== 'user.php?p=change_password'
is still true $current_file !== 'user.php?p=change_password'
的if语句仍然为true $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();
}
}
This solution worked 此解决方案有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.