Encode Your URL Parameters

If you wish to query a URL using the HTTP GET method, problems will arise if your parameters contain characters such as ? and &.

The solution is to use encodeURIComponent (client-side Javascript) or Server.URLEncode (ASP) or urlencode (PHP).

There is no need to do any extra work at the server side for Request.QueryString("...") or $_GET["..."].

encodeURIComponent example:

location.href = "page1.asp?id=" + encodeURIComponent(document.forms[0].text1.value);

References:

http://msdn2.microsoft.com/en-us/library/77tettz4.aspx
http://www.php.net/manual/en/function.urlencode.php
http://www.4guysfromrolla.com/webtech/042601-1.shtml

21 October 2006 | Software engineering, HTTP, Javascript, ASP, PHP | Comments

Comments:

  1.  
  2.  
  3.