Wednesday, November 7, 2012

Email Address ကို Verifying လုပ္ျခင္း

User ကကၽြန္ေတာ္တို႔ website မွာ Sign up လုပ္တဲ႔အခါ ကၽြန္ေတာ္တို႔က user email ကို confirmation code ကိုေပးျပီး verify လုပ္ခိုင္းေစခ်င္တယ္ဆုိရင္ေတာ႔
ဒီနည္းက အသံုး၀င္မယ္ထင္ပါတယ္

ဒီ Tutorial မွာေတာ႔ Php File ေလးခုနဲ႔ Database နွစ္ခုပါပါတယ္
1. signup.php
2. signup_ac.php
3. confirmation.php
4. config.php

ျပီးေတာ႔ Database နွစ္ခုေဆာက္မယ္
1. temp_members_db
2. registered_members

ဘာေတြလုပ္ဖို႔လိုလဲ?
1. User က sign up လုပ္တဲ႔အခါ ေပးဖုိ႔ confirmation code ကို random အေနနဲ႔ထားဖို႔လိုပါတယ္

2. User ရဲ႕ information နဲ႔ confirmation code ကိုသိမ္းဖို႔အတြက္ temp_members_db ဆိုတဲ႔ table ထဲမွာထည္႔ပါမယ္
    ဒါက confirmation code အတြက္ ယာယီသိမ္းဖို႔အတြက္ db table ေဆာက္ထားတာပါ
    ျပီးေတာ႔ email confirmation varify ျဖစ္ျပီးသြားတဲ႔ infomation ေတြကို registered_members ဆိုတဲ႔ table ထဲကိုေျပာင္းေပးဖို႔လိုပါတယ္
   
3. "temp_members_db" ဆိုတဲ႔ table ထဲကို data ထည္႔လို႔ျပီးသြားတဲ႔အခါ sign up လုပ္တဲ႔ user ေတြဆီကို confirmation code ကိုပို႔ေပးရမွာပါ
    တစ္ကယ္လို႔ User ရဲ႕ email လိပ္စာမွားေနတယ္ဆိုရင္ေတာ႔ ပို႔ေပးမွာမဟုတ္ပါဘူး
   
4. User က email ထဲမွာ confirmation link ကိုေတြ႔ျပီး click နွိပ္လိုက္တယ္ဆိုရင္ User ရဲ႕ account ဟာ active ျဖစ္သြားမွာပါ
   အဲလို active ျဖစ္ေအာင္လုပ္လိုက္တဲ႔အခ်ိန္မွာ temp_member_db ဆိုတဲ႔ table ထဲက data ေတြဟာ registered_members ဆိုတဲ႔ table ထဲကိုေျပာင္းလဲသြားမွာျဖစ္ပါတယ္
    ျပီးေတာ႔ temp_members_db ထဲမွာ User နဲ႔သက္ဆိုင္တဲ႔ data ေတြကို delete လုပ္ပစ္မွာေပါ႔ မဟုတ္ရင္ user မ်ားလာတဲ႔အခါ temp table ၾကီးက crash ျဖစ္သြားနိုင္ပါတယ္
    ဒါေၾကာင္႔ ရွင္းေနတာပဲ႔ေကာင္းတယ္
   
Step1 =>ပထမဆံုး "temp_members_db" နဲ႔ "registered_members" ဆိုတဲ႔ table နွစ္ခုကို database အသစ္တစ္ခုထဲ႔မွာထပ္ေဆာက္လိုက္မယ္
            temp_members_db ထဲမွာေတာ႔
            comfirm_code -> varchar(65)
            name            -> varchar(65)
            email             -> varchar(65)
            password        -> varchar(65)
            county           -> varchar(65)

            ဆိုျပီး Columns 5 ခုေဆာက္လိုက္ပါ manual နဲ႔ မလုပ္ခ်င္ဘူးဆိုလည္းေအာက္က code ကို sql ထဲကို ကူးထည္႔လိုက္ပါ
           
CREATE TABLE `temp_members_db` (
`confirm_code` varchar(65) NOT NULL default '',
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`password` varchar(15) NOT NULL default '',
`country` varchar(65) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


ျပီးေတာ႔ "registered_members ထဲမွာေတာ႔
            id             => int(4)     primary_key
            name        => varchar(65)
            email         => varchar(65)
            password   => varchar(65)
            country      => varchar(65)

            ဆိုျပီး columns 5 ခုထပ္ေဆာက္ေပးရပါမယ္ manual နဲ႔ မလုပ္ခ်င္ဘူးဆိုလည္းေအာက္က code ကို sql ထဲကို ကူးထည္႔လိုက္ပါ
           
CREATE TABLE `registered_members` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
`password` varchar(65) NOT NULL default '',
`country` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


ပထမအဆင္႔ေတာ႔ ျပီးသြားပါျပီ
Step2 => signup.php ဆိုတဲ႔ဖိုင္ကို  form ပံုစံနဲ႔ျဖစ္ေအာင္ ေရးေပးရပါမယ္

http://www.cyberoot.net46.net/verify_email/signup.php
 Source Code for signup.php

 _________________________________________________________________
 <table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form name="form1" method="post" action="signup_ac.php">
       <table width="100%" border="0" cellspacing="4" cellpadding="0">
              
            <tr>
                <td colspan="3"><center><strong>Sign Up </strong></center></td>
            </tr>
            <tr>
                <td width="76">Name</td>
                <td width="3">:</td>
                <td width="305"><input name="name" type="text" id="name" size="30"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td>:</td>
                <td><input type="text" name="email" id="email" size="30"></td>
            </tr>
            <tr>
                <td>Password</td>
                <td>:</td>
                <td><input type="password" name="password" id="password" size="30"></td>
            </tr>
            <tr>
                <td>Country</td>
                <td>:</td>
                <td><input type="text" name="country"  id="country" size="30"></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td><input type="submit" name="Submit" value="Register">&nbsp;<input type="reset" name="Reset" value="Reset"></td>
            </tr>
                          
        </table>

_____________________________________________________________

Step3 =>signup_ac.php ဖိုင္ကိုထပ္ေရးပါမယ္ သူကေတာ႔ data ေတြကို database ထဲ႔ထည္႔ဖို႔အတြက္ေရးတာပါ
            အဲဒီအဆင္႔မွာ
            1=>random confirmation code ကိုဖန္တီးရမယ္
            2=>confirmation code data ကို database ထဲ႔ထည္႔ရမယ္
            3=>confirmation link ကို user ဆီ email ပို႔ေပးရပါမယ္
            Source code ေလးတစ္ခ်က္ေရးရေအာင္
+++++++++++++++++++++++++++++++++++++++++++
<?php
include('config.php');


$confirm_code = md5(uniqid(rand()));
$name=$_POST['name'];
$email=$_POST['email'];
$password=md5($_POST['password']);
$country=$_POST['country'];

//insert data into database
$sql="INSERT INTO temp_members_db(confirm_code,name,email,password,country)VALUES
('$confirm_code','$name','$email','$password','$country')";
$result=mysql_query($sql);

//if success insertd data into database ,send confirmation link to email
if($result){
   
    $to=$email;
    $subject = "Your confirmation link here";
    $header="From:Cyberoot<cyberoot1@gmail.com>";
    $message="Your Comfirmation Link \r\n";
    $message.="Click on this link to active your account \r \n";
    $message.="http://www.cyberoot.net46.net/verify_email/confirmation.php?passkey=$confirm_code";
    $sendmail = mail($to,$subject,$message,$header);
}else
{
    echo "Not found your email in our database";
}
if($sendmail){
    echo "your Confirmation link Has Been Sent To Your Email Address.";
}else{
    echo "Cannot send Confirmation link to your e-mail address";
}
?>

  
+++++++++++++++++++++++++++++++++++++++++++++
Step4 => confirmation.php ဖိုင္ကိုထပ္ေရးမယ္ ဒီအဆင္႔မွာေတာ႔  User က Signup လုပ္ျပီး ကၽြန္ေတာ္တို႔ပို႔လိုက္တဲ႔ confirmation link ကိုေမးထဲ႔မွာေတြ႔ရမွာပါ
             ပို႔လိုက္တဲ႔ confirmation link မွာ confirmation.php ဆိုတာပါတယ္ျပီးေတာ႔ passkey လည္းထည္႔ထားေသးတယ္ေလ
             1. ->passkey ကိုတစ္ခ်က္စစ္ေပးရပါမယ္
             2. ->တစ္ကယ္လို႔ passkey က database ထဲ႔မွာရွိတယ္ဆိုရင္ေတာ႔ temp_members_db ဆိုတဲ႔ table ထဲကေနျပီးေတာ႔ registered_members ဆိုတဲ႔ table ထဲကိုအားလံုးေျပာင္းေပးရမွာပါ
             3. -> temp_members_db ထဲမွာရွိတဲ႔ passkey ကို delete လုပ္ေပးရပါမယ္

+++++++++++++++++++++++++++++++++++++++++++
<?php
include('config.php');
$passkey=$_GET['passkey'];


$sql1="SELECT * FROM temp_members_db WHERE confirm_code='$passkey'";
$result1=mysql_query($sql1);
if($result1){
    $count=mysql_num_rows($result1);
    if($count==1){
        $rows=mysql_fetch_array($result1);
        $name=$rows['name'];
        $email=$rows['email'];
        $password=$rows['password'];
        $country=$rows['country'];
       
       
        $sql2="INSERT INTO registered_members(name,email,password,country)VALUES
        ('$name','$email','$password','$country')";
        $result2=mysql_query($sql2);
    }else{
        echo "Wrong Confirmation Code";
    }
   
    if($result2){
        echo "Your account has been actived";
        $sql3="DELETE FROM  temp_members_db WHERE confirm_code='$passkey'";
        $result3=mysql_query($sql3);
    }
}
?>

++++++++++++++++++++++++++++++++++++++++++++++

Step5 => config.php ကၽြန္ေတာ္တို႔သံုးမယ္႔ Database နဲ႔ခ်ိတ္ေပးရမယ္႔အပိုင္းပဲ႔ျဖစ္ပါတယ္


+++++++++++++++++++++++++++++++++++++++++++++++
<?php

$host="mysql2.000webhost.com";
$username="a6357811_cyber";
$password="Cyberoot1";
$db_name="a6357811_email";


//Connect to server and select database.
$connection = mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
$database   = mysql_select_db($db_name)or die("cannot select DB");
mysql_query($database,$connection);

?>

++++++++++++++++++++++++++++++++++++++++++++++++

Thanks for Reading..
Written by cyberoot
www.cyberoot.blogspot.com
Ref:easyphpsetp    

No comments:

Post a Comment

Thanks for your comments
Welcome from cyberoot