2

I'm writing a web app in PHP that is basically a template designer. Users enter their measurements, colours, etc. in a form, and on submit they see a preview. All the defined variables show up in the URL (e.g. http://mysite.com/template.php?height=100&width=300&color=blue...)

I have about 100 such variables so needless to say the resulting URL can get pretty messy. Not that there's anything wrong with that, but I'm new to PHP so I was just wondering if there's a better way to do this? Does it slow down the browser unnecessarily to have 100 variables passing through a GET request?

Sam Nabi
  • 379
  • 3
  • 14

6 Answers6

5

Is there such a thing as too many variables in a PHP GET request?

Not directly, but a URL can be only 2083 characters long in Internet Explorer (definitely in versions up to 7, not 100% sure about 8 and don't know about 9). Similar limitations exist for older versions of Opera (I think 4kb) and some web servers.

Depending on your use case, consider storing the data in session variables instead.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Well, my `opera:config` says for "Maximum length of url": `2147483647` - but older versions were indeed limited. – mario Feb 04 '11 at 10:11
  • do you know if the URL limit persists in the IE 9 previews? – Andy E Feb 04 '11 at 10:13
  • @Andy E I don't know, I don't have it installed. On second look, it *may* have been relaxed in IE 8 already – Pekka Feb 04 '11 at 10:15
4

No, there is no maximum number of variables, but there is a maximum length of your URL. See:

What is apache's maximum url length?

Community
  • 1
  • 1
yankee
  • 38,872
  • 15
  • 103
  • 162
4

The problem with that is that certain browsers only support a fixed URL query size.

Can't you send it as a POST instead?

Check out IE, for example:

http://support.microsoft.com/kb/208427

And some older clients or proxy implementations only support up to 255 bytes...

xil3
  • 16,305
  • 8
  • 63
  • 97
  • With the POST method, how would I go about saving the current settings and coming back to it later on? With GET it's pretty easy to just copy the url and then go back to it later. – Sam Nabi Feb 04 '11 at 10:54
  • Well, if you need to save them for later use, you could use a SESSION (`$_SESSION`). – xil3 Feb 04 '11 at 11:01
4

Well, theoretically no, practically some Browsers set a limit to the length of a URL.

Stackoverflow - related thread

Community
  • 1
  • 1
Raffael
  • 19,547
  • 15
  • 82
  • 160
2

The only problem I see (and that I ran into once) is that there is a max-length restriction in some browsers: http://en.wikipedia.org/wiki/Query_string#Compatibility_issues

harpax
  • 5,986
  • 5
  • 35
  • 49
2

GET procotol is not designed to handle such request, because they where designed to GET static content.

Your content depends on some options and a POST would be more effective in any case.

By the way, you have to know that the GET protocol limits URL length, and it actually depends on the browser.

Boris Guéry
  • 47,316
  • 8
  • 52
  • 87