Miscellaneous in PHP

This tutorial will show you some validations we require in most of the cases. These are given below one by one.

1. Check if an email address is injected

//validate against any email injection attempts
function is_email_injected($email) {
    $injections = array('(\n+)',
        '(\r+)',
        '(\t+)',
        '(%0A+)',
        '(%0D+)',
        '(%08+)',
        '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if (preg_match($inject, $email)) {
        return true;
    } else {
        return false;
    }
}

Continue reading “Miscellaneous in PHP”

Codeigniter Transaction Example

Codeigniter transaction example will show you how we can use transaction in Codeigniter. We know that transaction is an important part of persistence storage media because we may save, update or delete data from persistence storage area.

For example, in database we may need to update multiple tables or we may require to delete from multiple tables, hence we may face some inconsistency during database tables updation or deletion from database tables. During updation few tables may be updated and few tables may not be updated. Similarly, in case of deletion few tables may get deleted and few may not. So data will be in inconsistent state.

Therefore, we want either a unit of work will be carried out completely or none. Hence the codeigniter transaction is required to make it happen consistently. Continue reading “Codeigniter Transaction Example”

Get Country information from IP address using PHP

This tutorial will show you how we you can get Country, City, State information from an IP address using PHP. Sometimes we are curious to know the details about a user who has been visiting the web page, then we can use this kind of application to log the visitor’s details into database.

In this tutorial I am passing the IP to an external URL which will actually fetch the information and I will extract the detail information from response HTML. Continue reading “Get Country information from IP address using PHP”