0

I'm hosting my PHP web site on a shared web hosting account, so I'm not sure what may be causing this since I don't have direct access to the server.

The page in question is very simple. Its PHP script receives data via a GET request and fills out the form on the page with it (as defaults before the user fills out the rest.)

For instance, it may accept a URL as such:

http://www.example.com/test.php?id=sendform&name=somename&ver=1.0&desc=some%20description

Then the PHP script reads parameters passed to it (via functions like stripslashes($_REQUEST['desc']);) and creates the HTML markup with form fields filled out with the data passed to it.

So this was working fine, until I noticed that if I pass a long URL (I don't know the exact limit, but for instance my test URL is 1,280 characters long) the script in my test.php does not execute and the page hangs up for a long time until the browser times out with an error.

I first thought that the stripslashes($_REQUEST['desc']); call was to blame, and thus I stripped out everything except a simply line:

print("Got to the end");

which still got hung up with a long URL.

So I'm curious, why is this happening? And how to prevent this "hang up"?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • It's to do with the `GET`. If you're sending large bodies of text, you need to send it via `POST`. – Darren Oct 16 '14 at 06:33
  • 1
    http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers – fortune Oct 16 '14 at 06:35
  • 1
    [`More Reading`](http://stackoverflow.com/q/2659952/2518525) – Darren Oct 16 '14 at 06:36
  • @Darren: Well, first off I'm well below that limit (of roughly 2K.) Secondly, I can't use POST. This request goes into a new browser window from a JavaScript in a Chrome extension. – c00000fd Oct 16 '14 at 06:38
  • Wasn't talking about the length aspect, more about the request size aspect (in `kb`) as per your web server settings. – Darren Oct 16 '14 at 06:39
  • @Darren: Oh, the server might have a GET request length limit after which it just poops out.. hah? – c00000fd Oct 16 '14 at 06:42
  • Yeah, I've run into this issue before and forgot the variables to change to fix it. The reason I suggested `post` was because you can send pretty large bodies via it without the issues you face with `GET`. – Darren Oct 16 '14 at 06:45
  • @Darren: I see. Good point. Thanks! – c00000fd Oct 16 '14 at 06:57
  • 1
    For those who are interested, here's how to open a new browser page with the `POST` request using JavaScript: http://stackoverflow.com/a/17793207/843732 – c00000fd Oct 16 '14 at 07:04

1 Answers1

0

You ideally shouldn't have long URLs as the recommended limit is to not have more than 256 characters including host as well. It is hard to figure out based on the information you have provided, but it could be possibly because of

  1. Browser (Check request trapping tools and see if the request is really being sent or getting blocked by browser itself.
  2. Server (Server may have limit over the url length in the configuration, you can check the access log OR error log to get the details)
  3. Settings at firewall (firewall at the server may be preventing such longer URL)

A suggestion is to avoid longer URL and if possible use POST method to send the data.

CuriousMind
  • 3,143
  • 3
  • 29
  • 54