Blog Archives

How should password information be stored?

Plain text is NEVER an option In last Christmas (2011), there was a breaking news (reported: 1, 2, 3) that over 6 million online user credentials were leaked out from CSDN, a popular China online community for programmers that stores user credentials in plant text, resulting in 50 million user accounts (users use the same credential […]

PHP isset() and multi-dimentional array

** The issue discussed in this post has been fixed since PHP5.4.0, so the below discussion and solution are for PHP 5.3.x or lower. Thanks David for clarifying. A few weeks ago I covered how to check the existence of an array element in PHP. In the post I explained why isset() is dangerous to […]

Really simple CSS compression function in PHP

Thanks to the simple syntax of CSS, we can easily compress the CSS code with a PHP function of only 3 lines of codes. Since the compression will remove all the code indention and comments so it should be apply to production codes only. Here is the CSS compression that I used in my projects. […]

Check if an array is associative or sequential(indexed) in PHP

In PHP, depending on the type of the keys in an array, the array can be identified as associative (if the key is a string like $arr[‘mykey’]) or sequential (some may call it indexed, i.e. if the key is an integer like $arr[1], $arr[2], etc.). Although the internal representation of both associative and sequential arrays […]

PHP – isset() vs array_key_exists() : a better way to determine array element’s existence

The story In the CourseYou project, we’re asked to check if an element is set in an array. That is,  we’re asked to determine whether $Arr[‘MyElement’] exists. So we use the following code as a start. <?php if (isset($Arr[‘MyElement’])) { … do my stuff … } ?> This code works fine, but, it works fine […]

Equal (==), identical (===) and array comparison in PHP

Equal (==) If you use equal (==), you are allowing type conversion which means PHP will try to convert the two sides into the same type and then do the comparison. So even if the two sides are NOT the same thing, they MAY still be treat as the SAME. Consider this code: <?php $left […]

Kohana 3.1.2

Kohana 3.1.2 is released.