OCTOBER 27TH, 2008
By MOHAMMAD SAJJAD HOSSAIN
I am a fan of CodeIgniter for its ease of use. I have developed several ecommerce projects using this “beautiful” framework. While working on my first ecommerce project with CodeIgniter, I faced a problem with URLs. The site was suppose to use both “http” and “https”. But with CodeIgnitor we can define one base URL, which can be either “http” or “https”. Then I came up with an idea and now I am going to share that idea with you.
What I am going to do…
We will create secure version of some functions. For this we will make changes in CodeIgnitor’s URL helper(url_helper.php), Config library (Config.php) and Config (config.php) files. We will be creating secure version of following functions:
- site_url()
- base_url()
- anchor()
- redirect()
Lets’ start…
First we will add the following config element in the config file:
$config['secure_base_url'] = 'https://examples.com'; |
Then, open the url_helper.php file (system/helpers/url_helper.php) and add the following codes. You may use a separate helper file if you do not want to alter the url_helper.php file.
if( ! function_exists('secure_site_url') )
{
function secure_site_url($uri = '')
{
$CI =& get_instance();
return $CI->config->secure_site_url($uri);
}
}
if( ! function_exists('secure_base_url') )
{
function secure_base_url()
{
$CI =& get_instance();
return $CI->config->slash_item('secure_base_url');
}
}
if ( ! function_exists('secure_anchor'))
{
function secure_anchor($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
if ( ! is_array($uri))
{
$secure_site_url = ( ! preg_match('!^\w+://! i', $uri)) ? secure_site_url($uri) : $uri;
}
else
{
$secure_site_url = secure_site_url($uri);
}
if ($title == '')
{
$title = $secure_site_url;
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
return '<a href="'.$secure_site_url.'" ' . $attributes . '>'.$title.'</a>';
}
}
if ( ! function_exists('secure_redirect'))
{
function secure_redirect($uri = '', $method = 'location', $http_response_code = 302)
{
switch($method)
{
case 'refresh' : header("Refresh:0;url=".secure_site_url($uri));
break;
default : header("Location: ".secure_site_url($uri), TRUE, $http_response_code);
break;
}
exit;
}
} |
Now, add the following code in Config.php file (system/libraries/Config.php):
function secure_site_url($uri = '')
{
if (is_array($uri))
{
$uri = implode('/', $uri);
}
if ($uri == '')
{
return $this->slash_item('secure_base_url').$this->item('index_page');
}
else
{
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
return $this->slash_item('secure_base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
}
} |
Now what we have…
Now what we have? We have secured versions of those function. You may now use them as their insecured version. Enjoy coding
.
JULY 15TH, 2008
By MOHAMMAD SAJJAD HOSSAIN
This class can be used to create email account and mail forwarders using PHP, without logging to cPanel. It is an extension of script made by www.zubrag.com. You can access the original link from here http://www.zubrag.com/scripts/cpanel-create-email-account.php. And it is also a modified version of the class “cpmail” which was coded by Md. Zakir Hossain (Raju), http://www.rajuru.xenexbd.com. How to configure:
- Download the zipped file.
- Unzip the file. This file contains the class file and an example file.
- Open the class file and change these variables -
- $currentTheme – Your cPanel theme
- $userName – Your cPanel user name
- $password – Your cPanel password
- $domain – Your cPanel domain
- $cPanelPort – Your cPanel port [optional]
- Include the class in the file where you want to use it.
Example:
// include the class file
include('class.cpmailmanager.php');
// create an instanse of the class
$cp = new CPMailManager();
// create an email account
$cp->createEmail('sadat', 'sadat123', 10);
if($cp->status) //account created successfully
{
echo 'Mail created successfully';
}
else
{
echo $cp->message;
}
// create mail forwarder
$cp->createForwarder('sadat', 'msh@example.com');
echo '' . $cp->message;
// delete mail forwarder
$cp->deleteForwarder('sadat', 'msh@example.com');
echo '' . $cp->message;
// delete email account
$cp->deleteEmail('sadat');
echo '' . $cp->message; |

APRIL 24TH, 2008
By MOHAMMAD SAJJAD HOSSAIN
Based on my last post on paging using PHP and MySQL, I have coded this class. It is very easy to implement and it will save your time. Here is a code snippet to show how simple to use it.
//include the class file
include('Pager.php');
//making connection to the database
mysql_connect('localhost', 'root', '');
mysql_select_db('test');
//prepare SQL
$sql = 'SELECT * FROM books';
//create an object of Pager passing the SQL
$pager = new Pager($sql);
//set the url. this is the current page
$pager->url = 'index.php';
//set number of rows. by default it is 10
$pager->rowPerPage = 5;
//build the pager
$pager->build();
//get paged data
$rows = $pager->getPagedData(); |
Click the download link given below for a copy of the class. It also includes an working example.

MARCH 13TH, 2008
By MOHAMMAD SAJJAD HOSSAIN
Date control is a combination of three drop downs with month, day and year valus. It can be used as an alternative to the date picker control. Suppose a user needs to select a date before/after 10 years. At this point selecting the date with a date picker will not be easy and time consuming. So, in this situation, this control may be helpful.

To customize you need you can configure it. Change the properties in date_control.js file.
How to use it?
1. Unzip the download
2. Link the date_control to the page you want to use it in.
3. Write this code where you want to place the control
<script language="javascript">
// getting the date control
getDateControl("name_of_the_field", "name_of_the_form");
</script> |
For more details see the demo.html file included in the download.
I have tested the code with Internet Explorer 6 and FireFox 2.X.X and it works fine.
You can download a copy from here: 
FEBRUARY 25TH, 2008
By MOHAMMAD SAJJAD HOSSAIN

This game is based on a paper game, Snake and Ladder. You may have played this game before. I have added nothing more. I have just programmed it for my nephews and nieces. They give me the inspiration for designing and programming this game. Hope you will like it.
Click this link if you want to download it 
FEBRUARY 25TH, 2008
By MOHAMMAD SAJJAD HOSSAIN

This is a puzzle game and it is freeware. You can freely distribute to your friends. It is mainly developed for children and for the beginners of computer operation. This will help them to improve their mouse movement. But anyone can play it and have fun. It is the first edition of the game. In this edition I have included 5 pictures’ puzzle. Hope you will enjoy the game.
To download a copy of the game click here 