Semicolons as URL Query Separators


#1

W3C recommends that all web servers support semicolon separators in the place of ampersand separators.

[quote=http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2]
B.2.2 Ampersands in URI attribute values

The URI that is constructed when a form is submitted may be used as an anchor-style link (e.g., the href attribute for the A element). Unfortunately, the use of the “&” character to separate form fields interacts with its use in SGML attribute values to delimit character entity references. For example, to use the URI “http://host/?x=1&y=2” as a linking URI, it must be written or .

We recommend that HTTP server implementors, and in particular, CGI implementors support the use of “;” in place of “&” to save authors the trouble of escaping “&” characters in this manner.[/quote]

They don’t seem to be working on my site. Should they? Can they be configured to work?

?username=John+Smith;toggle=True;username2=Bob+Roberts

[php]
GET: Array
(
[username] => John Smith;toggle=True;username2=Bob Roberts
)
[/php]

The standard ampersand works as expected:

?username=John+Smith&toggle=True&username2=Bob+Roberts

[php]
GET: Array
(
[username] => John Smith
[toggle] => True
[username2] => Bob Roberts
)
[/php]

But then, as this stackoverflow page points out, they don’t seem to work on Google either:

[list]
[]http://www.google.com/search?q=nemo&oe=utf-8
[
]http://www.google.com/search?q=nemo;oe=utf-8
[/list]


#2

That recommendation is from 1999, and has been pretty much universally ignored ever since. All browsers and most client libraries will always use “&” when constructing query strings; as such, most server software isn’t coded to recognize “;”.


#3

Thanks for the information! I’m good with using ‘&’, but I was just curious as to why ‘;’ wasn’t working. Now I know. Thanks!


#4

I, for one, have always programmed my own CGI scripts (in Perl) to support the use of semicolons as separators. (I think I started doing this around 1999 when that document was released, and have continued ever since.) Use of ampersands is problematic in HTML as the above document states, since you need to encode them in order for the page to validate.


#5

um, 1999, static html was all i knew. and i used tables for layout…

anyway, semicolons are certainly more readable and make more sense semantically. it’s too bad there’s not a setting to get php to recognise them. it would also save bandwith! One semicolon vs five characters for [font=Courier]&[/font]


#6

Supposedly, you can configure your server, folder, and/or individual script to support semicolon as a separator, although I haven’t any any luck with this. If anyone figures this out, please let us know what you did to get them to work.

http://www.w3.org/QA/2005/04/php-session#reference


#7

What you’d have to do to get this (mostly) working would be to set arg_separator.input to “&;” in php.ini.


#8

As a shared hosting client, can we modify php.ini directly for our site(s)? I assumed we would only be able to use the .htaccess and script-based overrides, which didn’t seem to work for me.


#9

You can. It’s easiest to do so using PHP 5.3, following the instructions at http://wiki.dreamhost.com/PHP.ini#PHP_5.3.