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
header
("Set-Cookie: hidden=value; httpOnly");
?>

However, browser compatibility is not complete. It is available in MSIE, but is lacking in Mozilla, Firefox and Safari. More discussion on the benefits of this cookie can be found on the Mozilla Bugzilla.

Read the full article (159 words)

Add comment August 11th, 2006

SQL Join syntax: Theta vs ANSI

At the heart of every dynamic website is some form of data source, whether it's a simple flat text file, XML schema, or full blown database. In this article, I'll be addressing database table joins with SQL (specifically MySQL).

Read the full article (614 words)

3 comments August 10th, 2006

Odd and Even Numbers

Sometimes its necessary to find out whether a number is odd or even. When I initially hit upon the problem, my immediate thought was to use the modulus function % and inspect the result.

However, a quick look at the PHP Manual showed a much easier way of determining whether a number is odd or even:


<?php
$status 
= ($number) ? 'Odd' 'Even';
?>

The '&' sign represents the bitwise 'AND' operator, and the appropriate user comment explains:

Read the full article (175 words)

Add comment July 13th, 2006

Regular Expressions in PHP

Regular Expressions (regex for short) appear to a lot of people as the 'black art' of coding. Most languages, be it PHP, Java, C, .NET, VB etc have a way of using regular expressions - and they can certainly make your job easier. So lets start on our journey into regular expressions. I am by no means an expert, but hopefully I'll be able to clear the fog that surrounds regular expressions!

Read the full article (1463 words)

Continue Reading 2 comments June 13th, 2006

Determining if a URL exists with Curl

Its quite common for people to enter in their URL when signing up - but what if you want to verify that this is a real page? You can validate the URL using a regular expression up to a point, but all that tells us is that the URL is well formed. What I wanted to do was to check that the page exists - i.e. that we don't get a 404 for it.

Luckily, this is quite easy if you have the Curl extension installed.

Read the full article (821 words)

Continue Reading 3 comments May 31st, 2006

Subdomain Link Cloaking

A common practice at the moment is to shorten affiliate links into a more useable format. For example, I have an affiliate link for 123-reg.co.uk which is www.123-reg.co.uk/affiliate.cgi?id=AF106554. However, if I want to share that link with someone, I have to login to my control panel, and get the link. It would be a lot nicer if I could offer a more memorable link like ukdomains.jellyandcustard.com.

This is in fact very easy to set up, however for those of you on shared hosts (without access to httpd.conf) your host will need to aid you in one or two steps.Here's how I did it:

Read the full article (322 words)

2 comments May 24th, 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
if ($handle opendir('/home/fernando/temp')) {
   while (
false !== ($file readdir($handle))) {
       if (
$file != "." && $file != "..") {
           print 
"$file <br />";
       }
   }
   
closedir($handle);
}
?>

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.

Read the full article (645 words)

2 comments May 18th, 2006

Installing PEAR

PEAR, the PHP Extension and Application Repository, has been around since 1999, and has several functions. According to the 'About PEAR' page:

The purpose of PEAR is to provide:

  • A structured library of open-sourced code for PHP users
  • A system for code distribution and package maintenance
  • A standard style for code written in PHP
  • The PHP Extension Community Library (PECL)
  • A web site, mailing lists and download mirrors to support the PHP/PEAR community

Getting Started

For most PHP coders, including myself at one point, PEAR seemed to be a bit of a mystery for those who shy away from object orientated programming. The first point to remember is this: you don't need OOP knowledge to use PEAR! Yup, no lies, you can use it if you have an ounce of intelligence, and can read the documentation! So, to calm the fear of PEAR, I'm going to take a step by step approach to installation, and the usage of several PEAR classes in a series of posts.

Read the full article (768 words)

Continue Reading 1 comment May 10th, 2006

PHP 5.1.4 released

A critical bug with $_POST array handling as well as the FastCGI sapi have been discovered in PHP 5.1.3. A new PHP release 5.1.4 is now available to address these issues. All PHP users are encouraged to upgrade to this release as soon as possible.

Permanent link to this article

Add comment May 5th, 2006

PHP 5.1.3 Released

After what seems like an eternity, PHP 5.1.3 has been released. Among the changes, the new release comes with improved date / time facilities, improvements to GD, CURL, SPL and a number of security fixes. More information can be found in the PHP Release Docs.

Along with this release sees a collection of PECL binaries available as a collection for Windows users. You can download PHP 5.1.3 from your closest mirror now!

Permanent link to this article

Add comment May 2nd, 2006

Previous Posts


Blogs.uk.com -->

Categories

Links

Calendar

April 2007
M T W T F S S
« Aug    
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Feeds


gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.