2

I am getting this error

Not Acceptable

An appropriate representation of the requested resource /admin/prc_res.php could not be found on this server.

Additionally, a 406 Not Acceptable error was encountered while trying to use an ErrorDocument to handle the request.

There is a $_POST['additionalinfo'] (from html teaxtarea) which is giving me this error. If I remove this, code works fine.

But why I am getting 406 error?

My index1.php in unnat1ir.in/cdn/

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>406 Error</title>
</head>
<p><form method="post" action="process.php">
<textarea name="test" rows="10" style="width:100%"></textarea><br>
<button type="submit">Check for 406 Error</button>
</form>
</p>
<p>This form is posted to <code>process.php</code>. In <code>process.php</code> I am just echo-ing <code>$_POST['test']</code> of the <code>textare with tinymce plugin</code>. <strong>If little amount of data is entered in textarea, no issues, BUT LARGE DATA will cause <code>406</code> error</strong></p>
<h1>Please check by inserting large <code>html</code> data </h1>
<body>
</body>
</html>

And process.php

<?
ini_set("log_errors", 1);
ini_set("error_log", "err.txt");
?>
<h1>The <code> echo ($_POST['test'])</code> is</h1>
<hr>
<code><? echo htmlentities($_POST['test']); ?></code>
<hr>

All the above codes working fine on localhost

A B Catella
  • 308
  • 4
  • 12
  • 3
    Can you create an [MVCE](http://stackoverflow.com/help/mcve)? Without that, I'm not sure we can do much but close this as a dupelicate of this: http://stackoverflow.com/questions/14251851/what-is-406-not-acceptable-response-in-http – HPierce Mar 06 '17 at 02:07
  • 1
    try to get the relevant part from web server error log the actual error is before the 406. 406 is not normally due to large data. also the 406 error generated is not by your script. it is a mis-configuration of the `404` page – bansi Mar 08 '17 at 06:14
  • @bansi Tried of error_log, and it is empty. No error details written into error_log file – A B Catella Mar 08 '17 at 06:22
  • that is odd (may be you are looking in wrong log file). which web server are you using? also are you using a browser? also check if you can find something in access log – bansi Mar 08 '17 at 06:25
  • How big are you speaking? I tried your form with 250k of text it is working. checked till 750k text and working and above 1M I get `Request Entity Too Large` error not 406 – bansi Mar 08 '17 at 06:31
  • @bansi No, its correct, I manualy setting error file. Now what I figured now putting just `
    //` in the textarea causes this error. Do I need ny `escape` things? new URL is unnat1ir.in/cdn/index1.php
    – A B Catella Mar 08 '17 at 06:41
  • @bansi my code in process.php is ` ini_set("log_errors", 1); ini_set("error_log", "err.txt"); ?>

    The var_dump($_POST['test']) is


    echo htmlentities($_POST['test']); ?>
    `
    – A B Catella Mar 08 '17 at 06:44
  • actually `><` is causing the problem may be you are doing something wrong while parsing that. can only say what is happening after looking in the code – bansi Mar 08 '17 at 06:57
  • @bansi added current code in question – A B Catella Mar 08 '17 at 07:04
  • your code don't generate the 406 error and is perfectly fine. there is something wrong in the configuration of the apache/php. and nothing comes to my mind on where to look – bansi Mar 08 '17 at 10:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/137536/discussion-between-bansi-and-a-b-catella). – bansi Mar 08 '17 at 10:28
  • I think I know what the problem is, but the links you provided don't work anymore. Do you have other links that demonstrate the problem? – Rei Mar 09 '17 at 08:08
  • @bansi Had over 90min of telephonic chat with my hosting provider. Finally they said, `it is some security policy like mod_security, we are not allowing some characters, we cant help you in this, bla bla blah.` (ACTUALLY THEY TOO DONT KNOW WHAT THE PROBLEM IS !!!). By the next day morning, forms started working. Ha ha haa..... – A B Catella Mar 10 '17 at 02:00
  • LOL, that is how 98% of the providers are. Nice to hear that everything is fine now. – bansi Mar 10 '17 at 02:30

6 Answers6

1

it is because you are not escaping some html characters that are entered through a textarea field like quotes etc. Try the code below it works.

mysql_escape_string($_POST['additionalinfo']);
0

This should be the problem with your php.ini config, try to edit

post_max_size=80M or something to increase the limit.

Đào Minh Hạt
  • 2,742
  • 16
  • 20
0

try this :

<?
ini_set("log_errors", 1);
ini_set("error_log", "err.txt");
?>
<h1>The <code> echo (htmlspecialchars($_POST['test']))</code> is</h1>
<hr>
<code><? echo htmlspecialchars($_POST['test']); ?></code>
<hr>

For more INformation

Amitesh Kumar
  • 3,051
  • 1
  • 26
  • 42
  • The code OP posted is perfectly valid. Have you noted the change you have made is in the HTML part of the code? – bansi Mar 08 '17 at 10:09
  • i also have local machine and there it is working fine i am trying find the solutions. – Amitesh Kumar Mar 08 '17 at 10:10
  • just try a apache restart. and check apache error log (not your log file) typically in `/var/log/httpd` folder in linux/mac machines and `logs` folder inside apache installation directory in windows – bansi Mar 08 '17 at 10:14
0

From the sound of it, this is resolved, but I thought I might give you some context.

406 Errors happen when the server is configured to reject requests that meet or don't meet certain conditions.

Your hosting provider was probably tinkering with it's mod_security rules and your form was triggering an unintended rejection from apache.

mod_security rules can be very convoluted and complex because they are generally configured on one line.

If security is a concern for you, you might want to check with your host if they disabled mod_security for your site or if they just reconfigured it.

You can check if mod_security is active on your site by uploading a file called phpinfo.php to your site that just contains <?php phpinfo() ?>.

Load the page in a browser and then search for mod_security. If it's there, then they just fixed their mod_security configuration.

If not, then they just removed it from your site.

Glad this got resolved.

Judd Franklin
  • 570
  • 2
  • 5
  • 16
0

I found that this error comes because you are trying to insert '±' this kind of values. If you remove this character and submit the form, your form will be submitted successfully. So the solution is you should use the ± instead of '±' this sign or you should use html symbol codes then only your information save into database.

iehrlich
  • 3,572
  • 4
  • 34
  • 43
Rishi_Rich
  • 21
  • 3
0

Try this code (see the opening tags):

<?php
ini_set("log_errors", 1);
ini_set("error_log", "err.txt");
?>
<h1>The <code> echo ($_POST['test'])</code> is</h1>
<hr>
<code><?php echo htmlentities($_POST['test']); ?></code>
<hr>
Just_Do_It
  • 821
  • 7
  • 20