3

I made a php registration & log-in script. Registration part is OK with Arabic and English characters.

However, Log-in with Arabic characters in not working while with English characters, it works.

Any hint for me to proceed please?

This is my code. I hope it is clear.

function login($username, $password){
$user_id = user_id_from_username($username);
$username = sanitize($username);
$password = md5($password);

return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0 ) == 1) ? $user_id  :false;}

function user_id_from_username($username){
$username = sanitize($username);
return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id');}

<?php

if (empty($_POST) === false) {
    $username = $_POST['username'];
    $password = $_POST['password'];

    if (empty($username) === true || empty($password) === true) {
        $errors[] = ' ◄ يجب آلا تكون الحقول فارغة!';
    } else if (user_exists($username) === false) {
        $errors[] = '◄   إسم المستخدم الذي أدخلته غير مسجل لدينا !!';
    } else if (user_active($username)=== false){
        $errors[] = '';
    } else {

        if(strlen($password) > 32){
            $errors[] = '◄  كلمة المرور غير صالحة ! ';
        }

        $login = login($username, $password);
        if ($login === false) {
            $errors[] = '◄   يوجد خطاء في البيانات التي أدخلتها.. تأكد من اللغة أو حالة الأحرف  !!';
        }else{
            //set the user session للمستخدم الحالي فقط
            $_SESSION['user_id'] = $login;
            // redirect user
            header ('location: challengersland-cboard.php');
            exit();
        }
    }
} else {
    $errors[] = 'عذرا، لم يتم إستلام أية بيانات.';
}


if(empty($errors) === false) {
?>
    <h3>▼ عذراً،حدثت الأخطاء التالية أثناء محاولتك تسجيل الدخول ▼</h3>
<?php

    echo output_errors($errors);
}
?>
Michael
  • 32,527
  • 49
  • 210
  • 370
ALBADI
  • 315
  • 2
  • 8
  • 17
  • 1
    Can you please show us your code? – Tim Biegeleisen Apr 28 '15 at 05:23
  • 1
    Don't restrict the length of passwords; it's bad design. Also, don't use md5() for password storage. – Ja͢ck Apr 28 '15 at 06:17
  • What does `sanitize()` do? – Ja͢ck Apr 28 '15 at 06:19
  • Potential duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Phil Apr 28 '15 at 06:32
  • Also, *mysql* bad, *mysqli* / PDO good – Phil Apr 28 '15 at 06:32
  • "Not work" isn't a sufficient problem description. You'll have to dig a little deeper than that and figure out what exactly doesn't work where. Debug! – deceze Apr 28 '15 at 06:46
  • comments are all considered. "does not work" means Arabic values in mysql can not be read or recognized. By the way, the problem only appear i upload the script in to host server. In local server every thing is OK. – ALBADI Apr 28 '15 at 06:55
  • What does "can not be read" mean exactly? What do you get exactly? Most likely you'll have to read this: http://stackoverflow.com/q/279170/476 – deceze Apr 28 '15 at 09:19
  • I am having the same problem. Any luck finding a solution? – FarrisFahad Sep 13 '16 at 17:59

0 Answers0