php - Activating user's accounts by mailing them -
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <body> <?php require_once('database_detail.php'); if(isset($_post['submit'])) { $dbc=mysqli_connect(cname,chost,cpwd,cdb); $username=mysqli_real_escape_string($dbc,trim($_post['username'])); $password=mysqli_real_escape_string($dbc,trim($_post['password'])); $confirm=mysqli_real_escape_string($dbc,trim($_post['confirm'])); $email=mysqli_real_escape_string($dbc,trim($_post['email'])); $phone=mysqli_real_escape_string($dbc,trim($_post['phone'])); if(!empty($username) && !empty($password) && !empty($confirm) && !empty($email) && !empty($phone)) { if($password==$confirm) { $query="select * user user_username='$username'"; $data=mysqli_query($dbc,$query); if(mysqli_num_rows($data)== 0) { $random=rand(1000,10000); $query="insert user(user_username,user_password,user_email,user_phone,date,random)". "values('$username',sha('$password'),'$email','$phone',now(),'$random')"; mysqli_query($dbc,$query); $message="account created successfully, kindly visit following link activate account"."\n"."localhost/login? activation=".$random; $to=$email; $subject="account activation"; mail($to,$subject,$message,'from:'.'xyz@gmail.com'); echo 'account created successfully. kindly visit email addres , activate account.'; exit(); } else { echo 'same username exists'; $username=""; } } else echo 'enter same password in both'; } else echo 'enter fields'; } ?> <fieldset> <legend>signup</legend> <form action="<?php echo $_server['php_self'];?>" method="post" > username:<input type="text" id="username" name="username" /> password:<input type="password" name="password" id="password" /> email<input type="text" name="email" id="email" /> contact number<input type="text" name="phone" id="phone" /> confirm password:<input type="password" name="confirm" id="confirm" /> </fieldset> <input type="submit" name="submit" value="sign up" /> </form> </body> </html>
so mailing user signs unique username password activation mail. generate random number, store particular random number in database of user , there's activation field in database either 0 or 1 ( not activated or activated). when user logs in , check activtion field, if ok continue, else check $_get[activation] field of url, if matches random number stored in database continue else return activation error. how or there's other way. how delete accounts havent been activated after period.
i not create activation key rand(). possible 2 persons same number.
so use sha1() username , current time.
for automatic deletion of inactivated accounts:
you create cronjob automatically checks difference between registration time , current time.
Comments
Post a Comment