简体   繁体   English

提交表单时禁止访问403

[英]Access Forbidden on Form Submission 403

There's definitely versions of this question out there, but none of them helped me solve my problem. 肯定有这个问题的版本,但是没有一个可以帮助我解决问题。

I'm prelearning PHP for a subject I'm taking this semester and I was testing a simple w3Schools example html file that goes like 我正在本学期学习一个学科的PHP,并且正在测试一个简单的w3Schools示例html文件,该文件类似于

<!DOCTYPE html>
<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  Name: <input type="text" name="fname">
  <input type="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // collect value of input field
    $name = htmlspecialchars($_REQUEST['fname']); 
    if (empty($name)) {
        echo "Name is empty";
    } else {
        echo $name;
    }
}
?>

</body>
</html>

When I get to the point where I submit the form, I get the 403 error. 当我提交表单时,出现403错误。 If I just echo $_SERVER['PHP_SELF'] it gives me the file name fine, it's just that if I put anything in the "action" section, I get the 403. I've tried configuring a virtual host and setting these properties 如果我仅回显$ _SERVER ['PHP_SELF'],它给我的文件名就很好,只是如果我在“操作”部分中输入了任何内容,我就会得到403。我尝试配置虚拟主机并设置这些属性

<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\site1"
ServerName site1
<Directory "C:\xampp\htdocs\site1">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order Deny,Allow
    Allow from all
    Require all granted
</Directory>

To no avail, I saw another post about urlencoding, but that shouldn't matter if I'm accessing local files should it? 无济于事,我看到了另一个关于urlencoding的帖子,但是如果我正在访问本地文件,那应该没关系吗? Any ideas or suggestions appreciated :) 任何想法或建议表示赞赏:)

Posted below is the error: 下面发布的是错误:

Access forbidden! 禁止访问!

You don't have permission to access the requested object. 您无权访问所请求的对象。 It is either read-protected or not readable by the server. 服务器对其进行了读保护或不可读。

If you think this is a server error, please contact the webmaster. 如果您认为这是服务器错误,请与网站管理员联系。

Error 403 错误403

site1 Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28 site1 Apache / 2.4.23(Win32)OpenSSL / 1.0.2h PHP / 5.6.28

Note I'm using xampp on windows 7 to do this. 注意我正在Windows 7上使用xampp来执行此操作。

EDIT: Reinstalling fixed the problem. 编辑:重新安装解决了问题。 I suppose it's possible that I broke something while editing the config files, would like to have known what it was that gave me a 403 though. 我想我可能在编辑配置文件时坏了一些东西,想知道是什么给了我403。

The error message tells exactly what the problem is. 该错误消息准确地说明了问题所在。 Try changing your file permission on your project. 尝试更改项目的文件权限。 Try this changing php write permissions in XAMPP on Windows 7 尝试在Windows 7上的XAMPP中更改php写入权限

Might be abit late, but I faced a similar problem today while trying to submit a form through POST. 可能会晚一点,但是今天我在尝试通过POST提交表单时遇到了类似的问题。 It would not allow me to submit a string that had a link and would through a 403 Forbidden Acess Denied error. 它不允许我提交具有链接的字符串,并且会通过403 Forbidden Acess Denied错误提交。

Disabling modsecurity (I did this from the control panel) solved it! 禁用modsecurity(我是从控制面板完成的)解决了它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM