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”