Archives for the 'PHP' Category

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 […]

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

Leaky PHP Session Variables

If you create a session variable, e.g. $_SESSION[”username”], it will conflict with a local variable named $username.
Therefore, the best practice would be to prefix all session variables with a leading underscore, e.g. $_SESSION[”_username”], so that they do not conflict with local variables.
Reference:
http://www.php.net/manual/en/ref.session.php#45534

19 October 2006 | Software engineering, PHP | 1 Comment