简体   繁体   English

PHP / Apache错误:406不可接受

[英]PHP/Apache Error:406 Not Acceptable

So I received this error today, I've narrowed it down to this issue: 所以今天我收到了这个错误,我已经将其缩小到这个问题:

My site is my musician page here . 我的网站是我的音乐家页面在这里 It allows people to come in and see photos of me, news, my music and events I'm playing at. 它允许人们进来看我的照片,新闻,我的音乐和我正在玩的事件。

Everything was going swell, I manually input data into MySQL to have it auto-feed to the home page. 一切都在膨胀,我手动将数据输入MySQL,让它自动提供给主页。 Now I'm adding the control panel so I can add, edit, delete things in the database from the web. 现在我正在添加控制面板,以便我可以从Web添加,编辑和删除数据库中的内容。

Everything works fine except for the ability to add/edit events. 除了添加/编辑事件的能力之外,一切正常。 I've narrowed it down to the fact that I can't input 2 URLs or I get this error. 我把它缩小到我无法输入2个URL或我收到此错误的事实。 I NEED to input 2 URLs (one to view the event page, one to buy tickets) but I can't input more than 1 at a time, is there anything I can do to correct or work around this error whether in apache or my code? 我需要输入2个网址(一个用于查看活动页面,一个用于购买门票)但我一次输入的数量不能超过1个,是否有任何我可以做的纠正或解决此错误,无论是在apache还是我的码?

<?php
    $specevlink = "http://facebooklink.com";
    $specgigtick = "http://ticketplacelink.com";
?>
     <form method="post" action="index.php?page=editgigs">
         <table>
                <tr>
                     <td>
                          Event Page (Link):
                     </td>
                     <td style="text-align: left;">
                          <input type="url" name="giglink" value="<?php echo $specevlink; ?>" />
                     </td>
                </tr>
                <tr>
                     <td>
                          Event Tickets (Link):
                     </td>
                     <td style="text-align: left;">
                          <input type="url" name="gigtick" value="<?php echo $specgigtick; ?>" />
                     </td>
                </tr>
         </table><br />
         <input type="submit" name="editgig" value="submit" /><br />
         <br />
     </form>

EDIT: 编辑:

I'm adding the full line of code so you can see exactly what I'm using, 我正在添加完整的代码行,以便您可以确切地看到我正在使用的代码,

Here's a pic of step 1 Here's a pic of step 2 这是第1步的图片。这是第2步的图片

This is included into an index.php file: 这包含在index.php文件中:

<?php
if(isset($_GET["page"])){
$page = $_GET["page"];
} else {
$page = "";
}

if($page === "editgigs"){
 include ('inc/logincheck.php');
?>
 <div class="label">
      EDIT GIGS
 </div><br />
 <div style="margin: 0 auto; text-align: center; width: 100%">
      <form method="post" action="index.php?page=editgigs">
<?php
      if(!isset($_POST['selectgigs'])){
           if(!isset($_POST['updgigs'])){
?>
                Select one of the options below:<br />
                <br />
                <select name="selgigs" style="max-width: 26%;">
<?php
                     while($gigsall_data = mysqli_fetch_array($gigsall_query)){
                          $gigid = stripslashes($gigsall_data['idgigs']);
                          $gigdate = stripslashes($gigsall_data['date']);
                          $gigname = stripslashes($gigsall_data['name']);
                          $gigdate = date('F j, Y', strtotime($gigdate));
?>
                          <option value="<?php echo $gigid; ?>">
                               <?php echo $gigdate; ?>: <?php echo $gigname; ?>
                          </option>
<?php
                     }
?>
                </select><br /><br />
                <input type="submit" name="selectgigs" value="Select" /><br />
                <br />
<?php
           }
      }
      if(isset($_POST['selectgigs'])){
           $gigtoed = trim($_POST['selgigs']);
           $specgig_query = mysqli_query($con, "SELECT * FROM `gigs` WHERE `idgigs` = '$gigtoed'") or die(mysqli_error($con));
           $specgig_data = mysqli_fetch_array($specgig_query);
           $specdate = stripslashes($specgig_data['date']);
           $specname = stripslashes($specgig_data['name']);
           $specevlink = stripslashes($specgig_data['evlink']);
           $specgigtick = stripslashes($specgig_data['ticklink']);
           $specnos = stripslashes($specgig_data['noshow']);
           if($specnos === '0'){
                $noshow = '';
           } else {
                $noshow = 'checked';
           }
?>
           <table style="border-spacing: 5px; padding: 10px;">
                <tr>
                     <td>
                          Past Event?:
                     </td>
                     <td style="text-align: left;">
                          <input type="checkbox" name="nos" <?php echo $noshow; ?> /> Past Event
                     </td>
                </tr>
                <tr>
                     <td>
                          Date:
                     </td>
                     <td style="text-align: left;">
                          <input type="date" name="gigdate" value="<?php echo $specdate; ?>" required />
                     </td>
                </tr>
                <tr>
                     <td>
                          Name:
                     </td>
                     <td style="text-align: left;">
                          <input type="text" name="gigname" value="<?php echo $specname; ?>" required />
                     </td>
                </tr>
                <tr>
                     <td>
                          Event Page (Link):
                     </td>
                     <td style="text-align: left; width: 350px;">
                          <input type="url" name="giglink" style="width: 100%;" value="<?php echo $specevlink; ?>" />
                     </td>
                </tr>
                <tr>
                     <td>
                          Event Tickets (Link):
                     </td>
                     <td style="text-align: left; width: 350px;">
                          <input type="url" name="gigtick" style="width: 100%;" value="<?php echo $specgigtick; ?>" />
                     </td>
                </tr>
           </table><br />
           <input type="hidden" name="gigid" value="<?php echo $gigtoed; ?>" />
           <input type="submit" name="updgigs" value="Update" /><br />
           <br />
<?php
      }
      if(isset($_POST['updgigs'])){
           $newid = trim($_POST['gigid']);
           $newdate = mysqli_real_escape_string($con, trim($_POST['gigdate']));
           $newname = mysqli_real_escape_string($con, trim($_POST['gigname']));
           $newlink = mysqli_real_escape_string($con, trim($_POST['giglink']));
           $newtick = mysqli_real_escape_string($con, trim($_POST['gigtick']));
           if(isset($_POST['nos'])){
                $newnoshow = mysqli_real_escape_string($con, '1');
           } else {
                $newnoshow = mysqli_real_escape_string($con, '0');
           }
           echo $newid.' '.$newdate.' '.$newname.' '.$newlink.' '.$newtick.' '.$newnoshow.'<br />';
           /*mysqli_query($con, "UPDATE `gigs` SET `date` = '$newdate', `name` = '$newname', `evlink` = '$newlink', `ticklink` = '$newtick', `noshow` = '$newnoshow' WHERE `idgigs` = '$newid' LIMIT 1") or die(mysqli_error($con));*/ //commented for testing
?>
           <div style="text-align: center;">
                <span class="confirm">
                     Successfully updated click <a href="index.php?page=events">here</a> to view it!
                </span>
           </div>
<?php
      }
?>
      </form>
 </div>
<?php
}

FYI- the logincheck.php is does nothing but check if the user is logged in, if not it sends them back to the home page. 仅供参考 - logincheck.php什么都不做,只检查用户是否已登录,如果没有,则将其发送回主页。

Your website is generating error if any user input item is starting with either http:// or https:// . 如果任何用户输入项以http://https://开头,则您的网站会产生错误。

When I try with a link starting with http:// I got a 406 Not Acceptable : 当我尝试使用以http://开头的链接时,我得到了406 Not Acceptable:

http://onkore.us/?blah=http://www.google.com http://onkore.us/?blah=http://www.google.com

It is fine when I try this : 我试试这个很好:

http://onkore.us/?blah=www.google.com http://onkore.us/?blah=www.google.com

You've mentioned that you are having problem if it is more than one link , but when I try with two links like below , it is being fine : 您已经提到过,如果它有多个链接,您就会遇到问题,但是当我尝试使用下面的两个链接时,它很好:

http://onkore.us/?blah1=www.google.com&blah2=www.google.com http://onkore.us/?blah1=www.google.com&blah2=www.google.com

However either you could find and fix the issue which might be specific to your server configuration or you could try a work around . 但是,您可以找到并修复可能特定于您的服务器配置的问题,或者您可以尝试解决此问题。

I am not sure if this workaround helps , but considering that http:// or https:// are creating the issue , what I am thinking is to remove the http:// and https:// from user input . 我不确定这种解决方法是否有帮助,但考虑到http://https://正在创建问题,我的想法是从用户输入中删除http://https:// First you might want to try changing <input type="url" to <input type="text" so that URL format is not enforced . 首先,您可能希望尝试将<input type="url"更改为<input type="text"以便不强制执行URL格式。 Then you could use Javascript to remove occurrences of http:// and https:// from the user input in the form before submitting to server . 然后,您可以使用Javascript在提交到服务器之前从表单中的用户输入中删除http://https://的出现。 Additionally you could remove these from the data before populating the form values . 此外,您可以在填充表单值之前从数据中删除这些。

Hope this helps . 希望这可以帮助 。

Regex : How to remove 'http://' from a URL in JavaScript 正则表达式: 如何从JavaScript中的URL中删除“http://”

This error means that for example, you are asking the server for books (And you only understand Spanish). 此错误意味着,例如,您要求服务器提供书籍(而您只懂西班牙语)。 The server only has English and German Books. 该服务器只有英文和德文书籍。
Therefore the server has your answer but it will not give it to you, because he knows you won't do anything useful or you will do something bad with it!! 因此,服务器有你的答案, 它不会给你,因为他知道你不会做任何有用的事情或你会做一些坏事! (like not reading the books and throwing them to people's heads, for example). (例如,不要阅读书籍并将其扔到人们的头上)。

406 Not Acceptable" is an unusual status code - the most common are 200, 404, 500, 301. You only see a 406 when something is wrong with the server, usually something silly but hard to diagnose. 406 Not Acceptable“是一个不常见的状态代码 - 最常见的是200,404,500,301。当服务器出现问题时,你只能看到406,通常是愚蠢但难以诊断的东西。

Also: 也:

This general error means the request you made was detected as a potential hack attempt to the server [...] 此一般错误意味着您所做的请求被检测为对服务器的潜在黑客攻击[...]
https://billing.stablehost.com/knowledgebase/178/What-does-406-Not-Acceptable-mean.html https://billing.stablehost.com/knowledgebase/178/What-does-406-Not-Acceptable-mean.html


The most common solution for this error is related with mod_security. 此错误的最常见解决方案与mod_security相关。

1. Mod_security 1. Mod_security

ModSecurity can monitor the HTTP traffic in real time in order to detect attacks [...] it operates as a web intrusion detection tool. ModSecurity可以实时监控HTTP流量,以检测其作为Web入侵检测工具运行的攻击。 ModSecurity can also act immediately to prevent attacks from reaching your web applications. ModSecurity还可以立即采取措施防止攻击到达您的Web应用程序。

This 406 error might be from mod_security as a response from a possible attack via POST, passing some url's instead of plain and normal text. 此406错误可能来自mod_security,作为来自可能通过POST的攻击的响应,传递一些url而不是普通和普通文本。

The most common solution is to disable the POST scan and mod_security filtering in htaccess: 最常见的解决方案是在htaccess中禁用POST扫描和mod_security过滤:

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

Also, in the terminal, execute: 此外,在终端中,执行:

sudo a2dismod security2_module 
sudo service apache2 restart 

To deactivate ModSecurity. 停用ModSecurity。

If that does not work, then edit the file 如果这不起作用,则编辑该文件

/etc/apache2/mod-security/modsecurity_crs_10_config.conf

And add a # at the beggining of the line that has something like this: 并在行的开头添加一个# ,如下所示:

SecDefaultAction “phase:2,log,deny,status:403,t:lowercase,t:replaceNulls,t:compressWhitespace”

Finally, restart apache 最后,重启apache

sudo service apache2 restart

I have been having this problem for a while and only once in a while, so it was hard to identify. 我有一段时间一直有这个问题,但偶尔也有一次,所以很难识别。

However, after some testing I have found the mistake in my case. 但是,经过一些测试后,我发现了我的错误。 It may be not in yours, but if anyone is having 406 Not Acceptable error it is worth a shot. 它可能不在您的身上,但如果有人有406 Not Acceptable错误,那么值得一试。

In my case that error occured whenever posted data had 'shell:' in it, which as I would guess is interpreted wrong and error is thrown. 在我的情况下,只要发布的数据中包含'shell:',就会发生错误,正如我猜的那样,它被解释为错误并且抛出了错误。 Solution for me was to replace that string before posting it. 我的解决方案是在发布之前替换该字符串。

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

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