FEBRUARY 12TH, 2009
By MOHAMMAD SAJJAD HOSSAIN
Sometimes we need to reverse engineer our database. Microsoft Visio has an option for reverse engineering. But by default it does not support MySQL or in other words you cannot reverse engineer a MySQL database. I have faced this problem and got the solution and sharing here with you.

The steps involved in this process are described below:
- Download the latest MySQL ODBC connector from MySQL site. You may find it here http://dev.mysql.com/downloads/connector/odbc/5.1.html.
- After downloading install the connector.
- Now open Microsoft Visio and open Database Model Diagram template (you may find it under Software and Database group).
- From Database menu click on Reverse Engineer. You will see the Reverse Engineer wizard.
- Click on the New button.
- Select System Data Source.
- Click Next.
- Select MySQL ODBC driver from the list.
- Click Next and then Finish. MySQL Connector/ODBC Data Source Configuration window will open.
- Give a name to the datasouce, database server host, user name, password and select the database you want to reverse engineer. Remember, the list of database will be shown if you have provided correct information.
- Click on Ok. Now you will find the data source in Data Source list.
- Select the newly created data source and click Next. The regular wizard for reverse engineering will start.
NOVEMBER 1ST, 2008
By MOHAMMAD SAJJAD HOSSAIN
OCTOBER 31ST, 2008
By MOHAMMAD SAJJAD HOSSAIN
When working with JavaScript in one of my projects I needed to trim strings and pad them. I googled for a solution and many sources I have got the following codes and sharing with you.
Trimming:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| //trimming space from both side of the string
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
//trimming space from left side of the string
String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
//trimming space from right side of the string
String.prototype.rtrim = function() {
return this.replace(/\s+$/,"");
} |
Using Trim Functions:
1
2
3
4
5
| //write the code given above
var str = " black ";
alert("a" + str.trim() + "b"); //result "ablackb"
alert("a" + str.ltrim() + "b"); //result "ablack b"
alert("a" + str.rtrim() + "b"); //result "a blackb" |
Padding:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| //pads left
String.prototype.lpad = function(padString, length) {
var str = this;
while (str.length < length)
str = padString + str;
return str;
}
//pads right
String.prototype.rpad = function(padString, length) {
var str = this;
while (str.length < length)
str = str + padString;
return str;
} |
Using Padding Functions:
1
2
3
| var str = "5";
alert(str.lpad("0", 5)); //result "00005"
alert(str.rpad("0", 5)); //result "50000" |
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.'">'.$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
.
AUGUST 26TH, 2008
By MOHAMMAD SAJJAD HOSSAIN

PHP Security
PHP is a very flexible language. But sometimes this flexibility creates security flaws because of improper use of it. I had just read an article “Top 7 PHP Security Blunders” by Pax Dickinson. It shows top 7 mistakes or flaws that may break site security.
“Security is a process, not a product, and adopting a sound approach to security during the process of application development will allow you to produce tighter, more robust code.” – Pax Dickinson
In this article the author has shown how PHP application be infected and how to protect it. He has described the followings with reference to different articles:
- Unvalidated Input Errors
- Access Control Flaws
- Session ID Protection
- Cross Site Scripting (XSS) Flaws
- SQL Injection Vulnerabilities
- Error Reporting
- Data Handling Errors
- Configuring PHP For Security
I found this article knowledgeable. Hope you will like it. You may read it from here http://www.sitepoint.com/article/php-security-blunders.
I want to conclude with lines from this article…
“…there are many things to be aware of when programming secure PHP applications, though this is true with any language, and any server platform. PHP is no less secure than many other common development languages. The most important thing is to develop a proper security mindset and to know your tools well…”
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;
