且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

提交简单的 PHP 表单时出现禁止错误

更新时间:2023-02-22 16:54:55

鉴于您能够发帖,并且您的发帖处理显然非常简单,因此不太可能抛出 403 错误或重定向到禁止的目录,我将冒险猜测您正在运行 apache 级别的防火墙.查看您的 apache 配置文件,并检查您是否正在运行 mod_security 或任何其他加载的防火墙模块.可以通过多种方式配置 mod_security,包括扫描 POST 数据以获取 html 内容并做出相应的反应.如果它配置为防止 html 注入,这可能是您的问题(请参阅此处的配置详细信息:http://www.modsecurity.org/projects/modsecurity/apache/feature_content_injection.html).

Given that you're able to post, and that your post-handling is apparently extremely simple and so unlikely to be throwing 403 errors or redirecting to forbidden directories, I'm going to hazard a guess that you're running an apache-level firewall. Have a look at your apache config files, and check to see if you're running mod_security or any other firewall module loaded. There are a number of ways mod_security can be configured, including scanning POST data for html content and reacting accordingly. If it is configured to prevent html injection, this may be your issue (see configuration details here: http://www.modsecurity.org/projects/modsecurity/apache/feature_content_injection.html).

要对此进行测试,请尝试将 htaccess 文件添加到您的 Web 根目录中(假设您可以使用 htaccess 覆盖 apache 设置)并设置:

To test this, try adding an htaccess file into your web root (assuming you're allowed to override apache settings with htaccess) and setting:

SecFilterEngine Off

重启apache,然后看看它是否仍然发生.

Restart apache and then see if it's still happening.

如果这是共享主机,或者您无法修改 apache 设置,您可以尝试使用 base64 在提交(onsubmit)之前对所有数据进行编码,然后在处理它的 php 脚本中使用 base64_decode($_POST[key]).

If this is a shared host, or you otherwise don't have the ability to modify apache settings, you can try a workaround using javascript that base64 encodes all the data before submitting (onsubmit), and then base64_decode($_POST[key]) in the php script that processes it.