php redirect to another domain

Suppose you have moved your site to a new domain (same server), then all the links related to the old site would be lost, including those bookmarked by your users.

In order to prevent showing 404 not found to the user, you can include a condition in your index.php file as below, to redirect the user to the corresponding page on the new site. You should include this code in the starting page of your application (normally index.php).

Note that you can also use a .htaccess file to perform redirection, as discussed here.


Implement a daily work logger application with php

I am presenting here, one of my recent php applications, that i developed in my free time.
This application enables you to log your daily work at your office. Just copy this application to your localhost and you are good to go.

Features of this application include add/edit/search entries, send email to any user with the weekly entries, etc. You can use the application as a diary script or an event calendar.

Download the application from github.

Don’t forget to modify the settings in config.php file.


HTTP Basic Authentication example

It is very easy to implement the basic HTTP authentication in your php web application.
Suppose you want to force the users to provide authentication credentials, when they visit a web page in your application. You can do that as easy as below code:


Upgrade php version on CentOS

In this post, i will list the steps required to update the php version from 5.3 to 5.4 or 5.5 on a CentOS Linux server, assuming that you have ROOT access to it.

First, go to this repo link RPM package list page.

There, you can choose to download the RPMS for php version 5.4, or 5.5, and move them to your server.
Not all the RPMs are required for your php installation, but the most common ones are: common. cli, gd, mbstring, mysql, pdo, mcrypt, etc. Here is a list of steps for installing few important RPM packages for PHP 5.5:

Once you have run the above commands, restart the Apache server and verify the PHP version. Done :)


Requests PHP Library

Recently i came across a fantastic PHP library for making HTTP calls to external URLs or web services.
The library is: Requests.

It can support HTTP calls of type: GET, POST, PUT, DELETE, etc. Here i am presenting an example of GET and POST, using the library. The best thing i liked about this library is that we can get the status code of the response and use it to determine the success of our request. If status code is 200, it means the request is Successful.


Add php support to Eclipse IDE and debug php scripts

If you are an experienced php developer, you might feel the need to debug your code and also develop the application code with the help of auto suggestions of an IDE. Eclipse is one of such good IDEs, which also supports PHP development, apart from Java (for which it is widely used).

Here i explain how can you add php support to Eclipse IDE and how to enable debugging of your php code using the Xdebug extension. I am using Eclipse Luna.

So first download Eclipse ( and open the Eclipse application. Follow the steps as highlighted in below screenshots (Click on images to enlarge them).









Now you have the PHP IDE environment ready for you!

In order to debug your code, you need to install an addon called XDebug for Eclipse.

Go to:, and paste your phpinfo() output there. Then when you analyse your phpinfo() output, it will provide few instructions similar to the below lines. You need to follow them to install the Xdebug support for PHP.

1. Download php_xdebug-2.3.3-5.4-vc9.dll
2. Move the downloaded file to \xampp\php\ext
3. Edit C:\xampp\php\php.ini and add the line
4. zend_extension = \xampp\php\ext\php_xdebug-2.3.3-5.4-vc9.dll
5. Restart the webserver

The following links might be useful:

So once you have XDebug ready with your PHP (Look in your phpinfo() output), go ahead and configure that in your Eclipse.


Done :)


wordpress make user super admin from database

Here i am listing the steps to make a normal user of your wordpress site into a super administrator, from the backend (say, using phpmyadmin).

First, note down the user id of the user, whom you are trying to make the super admin. Then get his user level. Each user is assigned a level, based on his role. Reference.

Now you need to update the user level to 8, 9 or 10, in order for the user to have the administrator role.

Next, determine the current capabilities of the user.

It would be something like: a:1:{s:11:”contributor”;b:1;}

Now you need to run the below query, to set the user capabilities to that of a super admin user.

Done :)


php captcha code validation

Here is a simple code to display a form with captcha code validation in place. The code is divided into 2 files, one file with the form and the other file that generates random text as captcha image.

You can download the 2 files as a zip archive, from here.

And here is the Demo.


Install and uninstall LAMP packages on CentOS

Install LAMP packages:
# yum install httpd -y
# service httpd start
# chkconfig httpd on
# yum install mysql mysql-server -y
# service mysqld start
# chkconfig mysqld on
# mysql_secure_installation
# yum install php -y
# service httpd restart
yum install php-mysql -y
# service httpd restart
# vi /var/www/html/test.php > phpinfo();

Uninstall LAMP packages:
service httpd stop
service mysqld stop
yum erase httpd httpd-tools apr apr-util
yum remove php
yum remove php-common
yum remove mysql-server
yum remove mysql


hosting web tutorials