通过同一页面上的短信通知用户其密码已更改(使用 PHP 或 AJAX?)

发布于 2024-09-18 12:45:56 字数 179 浏览 5 评论 0原文

这是场景。用户想要更改他的密码。因此,他登录并填写了所需的新密码,然后单击“提交”。后端PHP检查他的代码并在MySQL数据库中更新它。用户被带回同一页面(带有表单),并通过页面顶部的这一小段通知其密码已成功更改。

是否可以仅使用 PHP(不使用 jQuery)来执行此操作?

如果我的问题措辞不好,我深表歉意。

Here is the scenario. A user wants to change his password. So he login and fill up his new desired password and clicked submit. Back end PHP checks his codes and updated it in MySQL database. User is brought back to the same page (with the form) and is notified by this small paragraph sitting on the top of the page that his password has been changed successfully.

Is it possbile to do this with PHP only (without jQuery)?

Apologies if I had phrased my question poorly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小梨窩很甜 2024-09-25 12:45:56

您也可以不使用 AJAX。

您可以通过在会话中维护一些标志来做到这一点。
当后端更改用户密码时,设置$_SESSION['passwordChanged'] = true。

在页面启动时检查是否设置$_SESSION['passwordChanged']真的
然后显示您的密码已更改的 DIV 并重置会话变量 $_SESSION['passwordChanged'] = false;

You can also do without use of AJAX.

you can do this by maintaining some flags in session.
when user's password is changed at back end , set $_SESSION['passwordChanged'] = true.

On start up of page check whether $_SESSION['passwordChanged'] is set TRUE
then display a DIV that your passwordd is changed and reset session variable $_SESSION['passwordChanged'] = false;

小霸王臭丫头 2024-09-25 12:45:56

是的,使用 AJAX 是可以的。如果 PHP 后端返回成功,请更新 div (或任何其他相关元素)以显示成功的密码更改。

Yes, it is possible by using AJAX. If the PHP backend returns a success, update a div (or any other element for that matter) to display successful password change.

嘿嘿嘿 2024-09-25 12:45:56

如果您也希望在没有 JavaScript 的情况下完成此工作,请设置一个会话变量。因此,在您的逻辑中,您将拥有(伪代码):

$sql = "UPDATE user SET password = ?";
$db->prepare($sql);
$db->execute(array($_POST['password'])); // password would also be hashed, presumebly
if ($db->rowCount()==1) {
    $_SESSION['password_changed'] = true;
}

然后在您的页面上将用户重定向到标题中的内容:

if ($_SESSION['password_changed']) {
    $message = "";
    unset($_SESSION['password_changed']); // no longer needed
}
if (strlen($message) > 0) {
    echo '<p class="message">' . $message . '</p>';
}

然后使用 JavaScript,在页面加载时隐藏消息并对其执行您想要的操作,无论它是否淡出消息输入,或放下消息等。

If you want this work without JavaScript too, then set a session variable. So in your logic, you would have (pseudo code):

$sql = "UPDATE user SET password = ?";
$db->prepare($sql);
$db->execute(array($_POST['password'])); // password would also be hashed, presumebly
if ($db->rowCount()==1) {
    $_SESSION['password_changed'] = true;
}

Then on your page you redirect your user to, this in the header:

if ($_SESSION['password_changed']) {
    $message = "";
    unset($_SESSION['password_changed']); // no longer needed
}
if (strlen($message) > 0) {
    echo '<p class="message">' . $message . '</p>';
}

Then with JavaScript, hide the message on page load and do what you want with it, whether it's fading the message in, or dropping the message down etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文