【问题标题】:Can I use .HTACESS to submit an Html form?我可以使用 .HTACCESS 提交 Html 表单吗?
【发布时间】:2019-06-07 17:06:10
【问题描述】:

我正在尝试找到一种通过 .HTACCESS 将 404 和 503 错误(以及类似类型)重定向到页面的方法,但会添加一些附加值。

示例 - 如果有人登陆 404 错误页面,链接通常如下所示: https://www.yourdomain.com/pages/404

你会如何得到它:
https://www.yourdomain.com/pages/404?submit=error&msg=3
(在 POST 或 GET 数据中)

这个问题翻译了我正在寻找的部分内容,但并不完全(因为答案显然是“否”): Can I use .htaccess to convert a url slug to a POST request?

这可以做到吗,如果这样做会不会有任何安全隐患?

这是在error_page.php中:

    if ((isset($_GET['submit']) && $_GET['submit'] == 'error') || (isset($_POST['submit']) && $_POST['submit'] == 'error')) {

    $success_message = mysqli_real_escape_string($conn, $_POST['msg']);

    switch ($success_message) {
        case '2':
            echo "<h2>Page under Maintenance</h2>";
            echo "<p>This page is currently undergoing some critical maintenance. You can try again in a couple hours.</p> For any help or enquiries send us a message on ".$support_email."";
            break;
        case '3':
            echo "<h2>404 Page Not Found</h2>";
            echo "<p>It seems the page you're looking for doesn't exist...</p>";
            mail($errors_email, 'Alert: 404 Not Found', 'A user (ref '.$user_ref.' with IP address '.$ip_address.') landed on this page ('.$current_url.') from '.$previous_url.' with a 404 error. Care to see what went wrong?');
            break;  
        default:
            mail($errors_email, 'User Landed on an Unknown Error Page', 'A user ('.$user_ref.') landed on the success_template.php page and something went wrong. This is just an alert to test all of the forms pointing to this page to see if they are valid.');
            break;
        }
    }

【问题讨论】:

  • @mplungjan 我会检查的,谢谢。 (我意识到,如果您精通某事,您将能够在 Google 上找到任何东西。作为一个初学者,甚至不知道这是否可能,我什至用一千次谷歌搜索都找不到它。)跨度>
  • 我不确定这是否可能,我只是想给你一个相关的搜索

标签: php html .htaccess


【解决方案1】:

您需要自己的 php 脚本来处理重定向: 例如:handle_redir.php404.php 等。

在您的 .htacces 中,您可以将 404 503 错误...等重新分配到您的 handle_redir.php

ErrorDocument 404 http://%{HTTP_HOST}/handle_redir.php?%{REQUEST_URI}

ErrorDocument 404 http://%{HTTP_HOST}/handle_redir.php?submit=error&amp;msg=3

然后在你的脚本handle_redir.php你可以使用

if(isset($_GET["submit"]) &amp;&amp; $_GET["submit"] == "error") //do something

【讨论】:

  • 天哪,这正是我想要的。 POST 和 GET 表单的两个示例 ({REQUEST_URI}) 有区别吗?
  • 是的。 htaccess 不对发布数据做任何事情。它适用于网址。
  • 使用{%REQUEST_URI},您会收到来自客户端的原始请求:例如:如果用户发布或获得http://your_domain.com/path1/path2?variable1=value1&amp;variable2=value2,那么在{%REQUEST_URI} 中您会收到/path1/path2?variable1=value1&amp;variable2=value2
  • 另一个提示:如果要很好地实践这一点,但在现实世界(生产站点)中,请记住:永远不要相信来自客户端的数据......所以在你的 SQL 查询之前检查每个 $ _POST 。 . $ _GET 如果包含预期的字符。 .. 看看:w3schools.com/sql/sql_injection.asp 还搜索有关 PDO 和准备好的声明的信息
  • 是的,这只是为了测试目的。一旦上线,将全力以赴进行 SQL 注入保护 :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-19
  • 2011-03-19
  • 1970-01-01
  • 2016-05-27
  • 2021-01-01
  • 1970-01-01
相关资源
最近更新 更多