اذهب إلى المحتوى

Ahmed Charafeddine Meftah

الأعضاء
  • المساهمات

    3
  • تاريخ الانضمام

  • تاريخ آخر زيارة

أجوبة بواسطة Ahmed Charafeddine Meftah

  1. إن كنت تريد أن يتم التحقق من صحة الإيميل عبر رابط يتم ارساله الى الإيميل المسجل، كل ما عليك فعله هو : 

    - اضافة حقلين hash و active (الملف المرفق 1)

    active = 0 معناه لم يتم تأكيد الحساب active = 1 تم تأكيد الحساب

    - عند التسجيل يتم توليد كود مميز (hash)  يتم تخزينه في القاعدة الى جانب active = 0

    // توليد هاش عشوائي
    $hash = md5( rand(0,999999) );

    - تسجيل العضو :

    mysql_query("INSERT INTO users (username, password, email, hash) VALUES(
    '". mysql_escape_string($name) ."', 
    '". mysql_escape_string(md5($password)) ."', 
    '". mysql_escape_string($email) ."', 
    '". mysql_escape_string($hash) ."') ") or die(mysql_error());

    ارسال معلومات التسجيل الى الايميل + رابط التفعيل : 

    $to      = $email; 
    $subject = 'Signup | Verification'; 
    $message = '
     
    Thanks for signing up!
    Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
     
    ------------------------
    Username: '.$name.'
    Password: '.$password.'
    ------------------------
     
    Please click this link to activate your account:
    http://www.yourwebsite.com/verify.php?email='.$email.'&hash='.$hash.'
     
    ';
                         
    $headers = 'From:noreply@yourwebsite.com' . "\r\n"; 
    mail($to, $subject, $message, $headers);

    - وهكذا عند الضغط على رابط التأكيد : 

    mysql_connect("localhost", "tutorial", "password") or die(mysql_error());
    mysql_select_db("registrations") or die(mysql_error());
                 
    if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) && !empty($_GET['hash'])){
        // Verify data
        $email = mysql_escape_string($_GET['email']);
        $hash = mysql_escape_string($_GET['hash']); 
                     
        $search = mysql_query("SELECT email, hash, active FROM users WHERE email='".$email."' AND hash='".$hash."' AND active='0'") or die(mysql_error()); 
        $match  = mysql_num_rows($search);
                     
        if($match > 0){
            mysql_query("UPDATE users SET active='1' WHERE email='".$email."' AND hash='".$hash."' AND active='0'") or die(mysql_error());
            echo 'تم تفعيل حسابك بنجاح';
        }else{
            echo 'خطأ : لم يتم تفعيل حسابك';
        }
                     
    }else{
        echo 'خطأ ...';
    }

     

    db.jpg

    • أعجبني 1
×
×
  • أضف...