Posts filed under 'PHP 5'

httpOnly cookies in PHP

Ilia, one of the PHP developers, has included a patch by Scott MacVicar into CVS for PHP 5.2 that allows you to set a httpOnly cookie instead of a normal cookie. A httpOnly cookie allows you to set a cookie that isn't accessible via Javascript, and so removes the possibility of some nefarious code to try and read your cookie.

This can be enabled in PHP 5.2. by passing TRUE as the 7th paramenter in setcookie() and setrawcookie(). In versions below 5.2, you can set this by passing an additional header.

PHP:
  1. header("Set-Cookie: hidden=value; httpOnly");

Add comment August 11th, 2006

Using DirectoryIterator to List Files in PHP

During the days of PHP4, the most common way of showing the files in a directory was like so:

PHP:
  1. if ($handle = opendir('/home/fernando/temp')) {
  2.    while (false !== ($file = readdir($handle))) {
  3.        if ($file != "." && $file != "..") {
  4.            print "$file <br />";
  5.        }
  6.    }
  7.    closedir($handle);
  8. }

However, if your PHP version has now been upgraded to PHP 5, you can take advantage of DirectoryIterator instead. This class (don't get scared) is part of the SPL library that is now bundled within PHP 5.

10 comments May 18th, 2006


Calendar

May 2008
M T W T F S S
« Sep    
 1234
567891011
12131415161718
19202122232425
262728293031  

Posts by Month

Posts by Category