PHP function to check valid date

I have written a PHP function to check a supplied string is a valid date or not. Lets have a look into the code.

 * The function is_date() validates the date and returns true or false
 * @param $str sting expected valid date format
 * @return bool returns true if the supplied parameter is a valid date 
 * otherwise false
function is_date( $str ) {
    try {
        $dt = new DateTime( trim($str) );
    catch( Exception $e ) {
        return false;
    $month = $dt->format('m');
    $day = $dt->format('d');
    $year = $dt->format('Y');
    if( checkdate($month, $day, $year) ) {
        return true;
    else {
        return false;

Let’s use and improve the function.

Writing review on the book- “Kohana 3.0 Beginner’s Guide”

Kohana Book

One year back I have written a post on Kohana and CodeIgniter. In that post, I wrote I like Kohana than CodeIgniter. Kohana is an open source, object oriented MVC web framework built using PHP5 by a team of volunteers that aims to be swift, secure, and small. Kohana is changing rapidly. But still Kohana does not have good documentation. Few weeks ago I have found a book on Kohana titled Kohana 3.0 Beginner’s Guide from Packt Publishing.

I am going to write a review on this book. I hope it will be helpful to the young programmers.

You can find some more information on Kohana from the following links.

Kohana and CodeIgniter PHP Framework

Kohana: the swift PHP frameworkCodeIgniter is a powerful PHP framework. I have been working on CodeIgniter for more than 2 years. I suggested lot of my friends to learn CodeIgniter. Few months back I started working on Kohana PHP framework. The slogan of Kohana is nice – “The Swift PHP Framework”. I liked Kohana at the first sight.

I developed several web application using Kohana and became a big fan of Kohana. Here I would like to show you some code segments of both frameworks. CodeIgniter

Continue reading “Kohana and CodeIgniter PHP Framework”

PHP Security Tips and Tools

I was reading on the topic “php security” using Google Reader. I hope it helps everyone to defining PHP security and it’s uses. Here I would like to quote some paragraphs from the original post on

PHP is the most popular web programming languages in use today due in large part to the fact that it’s a highly flexible syntax that can perform many functions while working flawlessly in conjunction with html – Plus it’s relatively easy to learn for beginners, yet it’s powerful enough for advanced users as well. It also works exceptionally well with open source tools, such as the Apache web server and MySQL database. In other words, its versatility is unsurpassed when compared to other scripting languages, making it the language of choice for many programmers.

There are various types of attacks that PHP is particularly vulnerable to. The two main types of attacks are human attacks and automated attacks – Both of which can potentially devastate a website. The goal of PHP security is to minimize, and ultimately eliminate, the potential for both human and automated attacks by putting into place strategic lines of defense to eliminate access to your site by unverified users. The way you go about doing this is to target the most common types of PHP security breaches first, so that you make your website airtight against malicious attacks. So what are the most common types of PHP security breaches?

Most Common PHP Security Vulnerabilities

1. Register_Globals

Register_Globals makes writing PHP applications simple and convenient for the developer, but it also poses a potential security risk. This setting is located in PHP’s configuration file, which is php.ini, and it can be either turned on or off. When turned on, it allows unverified users to inject variables into an application to gain administrative access to your website. Most, if not all, PHP security experts recommend turning register_globals off. Continue reading “PHP Security Tips and Tools”

Open Flash Chart :: amazing chart generating application

Now a days I am working in Open Flash Chart (OFC). I found this amazing, easy to generate chart and use in web applications. Flash produces high quality graphics. OFC generates high resolution charts, I think you like this very much. Lets take a look into a screenshot.

OFC generated chart
OFC generated chart

Click on the thumbnail to view actual size. You may visit OFC homepage, try the tutorial to lean how to make chart using open flash chart. Here your find some sample charts. OFC has two sets of chart library, version 1 and version 2. I think version 2 is better than version 1. Here is the download link of OFC version 2. OFC tutorial is very much easy to understand.

OFC includes some other tools, swfobject, and JSON for data files. And also includes Server Side Helper Libraries for PHP, Perl, Python, Ruby, .NET, Google Web Toolkit and JAVA to generate hassle free JSON formatted data.

I hope you enjoy OFC.

Talking with PHP

Talking with PHP
Talking with PHP

I need the current time then I call the php function – time() and get the current Unix timestamp. Then function time() returns the second measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). Say for, in my website users can register for free for one year. I need to calculate an account expiration time after one year. How can I calculate the expiration time. I need to add one year with the account creation time. We may get the the date and time of account expiration using following code.

[sourcecode language=”php”]$expiration = date( ‘Y-m-d H:i:s’, time() + (365 * 24 * 60 * 60) );[/sourcecode]

I have another easy solution. See bellow.

[sourcecode language=”php”]$expiration = date(‘Y-m-d H:i:s’, strtotime( ‘now + 1 year’ ) );[/sourcecode]

Everyone knows PHP is a flexible language. In the second statement, it seems I am talking with php. ha ha ha

CakePHP Manual in PDF Format

“Cake is a rapid development framework for PHP which uses commonly known design patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.”

Manual for CakePHP is available here – in HTML format. I converted that into PDF. This will help those who likes more to read PDF than HTML.
Download CakePHP Manual in PDF Format


Thanks Hasin Vai, I am including your links here

My first osCommerce contribution

Hi all,

Now a days I am working on osCommerce. Recently I am working on Online Calling Card /Phonecard Selling. I developed it in osCommerce (the leading opensource online shopping cart tools in php). I used a module named Unique Virtual Products.

I modified it a littlebit and posted to osCommerce contribution section.

You may download it from here Unique Virtual Products 0.7.

Cheers !