【问题标题】:Form querying from table if correct username and password are chosen opens up to php file on server如果选择了正确的用户名和密码,则从表中查询表单将打开服务器上的 php 文件
【发布时间】:2019-09-20 15:48:20
【问题描述】:

在表单中提交正确的用户名和密码后如何重定向到index.php。

【问题讨论】:

  • 使用AJAX验证密码,然后使用window.location = "index.php";
  • 如果凭据正确,则只需提交不带 Ajax 的表单并在服务器上设置 Location 标头(在处理登录请求的 PHP 脚本中)。这将导致浏览器在收到响应中的标头时进行重定向。您可以非常轻松地在 Google 上了解更多信息

标签: javascript php html


【解决方案1】:

以下是我保存的一些链接,供我自己参考,应该对您有所帮助。如果您已经知道这些答案中的大部分信息,请原谅我 - 希望在答案/示例中有一些重要的部分会有所帮助。

Login into a website and get html from a page

How to create an admin page to add/remove elements to a drop-down list?

Restrict access to private images

基本上有两种可能。

如果您使用的是由后端文件处理的非 ajax 表单,您只需输出重定向到其他页面。在 PHP 中,只需:

header('Location: new_page.php');

如果您使用 AJAX(将用户输入的名称/密码数据发送到后端文件,该文件检查它们并返回响应),那么您将在 ajax .done() 函数中获得成功/失败信息 - - IE。在 JavaScript 中。在这种情况下:

.done(function(recd){
    if (recd == 'yes'){
         window.location.href = 'http://example.com/new_file.html';
    }
});

【讨论】:

    猜你喜欢
    • 2017-07-31
    • 2013-07-17
    • 2014-06-17
    • 1970-01-01
    • 2012-06-29
    • 2011-11-25
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    相关资源
    最近更新 更多