This video to illustrates, verification of user email ID by sending a unique URL to be clicked by the user inorder to active his account, to further use the application.
Use
We can restrict certain features of our application for the accounts which has not been verified.
By this we can know if the email ID is valid and authorized user is using it and no one else.
Database
mysql> create database test;
mysql> use test;
mysql> create table login(
name varchar(25) not null,
pass varchar(60) not null,
email varchar(30) primary key,
phn varchar(15),
rndm varchar(20) not null,
actv int not null);
Note: Do not make phno as integer, as it can’t handle huge numbers like 9844552841 (if its a phone number!)
email is concede red as Primary Key, as we can identify each user uniquely via this attribute. No two user can have the same email id.
Database connection script
db.php
< ?php
mysql_connect('localhost','DatabaseUsername','DatabasePassword');
mysql_select_db('DatabaseName');
?>
Registration Code:
register.php
The user input will be passed to save.php via post method.
save.php
< ?php include_once('db.php'); ?>
< ?php
$n = $_POST['n'];
$p = md5($_POST['password']);
$email = $_POST['email'];
$phn = $_POST['phn'];
$rndm = rand(34565, 993240);
$sql ="INSERT into login values('$n','$p','$email','$phn', '$rndm', '0')";
if(!mysql_query($sql))
echo "Not updated..".mysql_error();
else
{
$url = "http://yourdomainname.com/reg/activate.php?act=$rndm&email=$email";
$cont = "click this link $url To activate your account";
if( mail($email, "Activate Account!", $cont, "From: satish@yourdomain.com") )
echo 'Please visit your email to activate your account
After Activation, log into your account';
else
echo 'Registration failed..please try again';
}
?>
change yourdomainname.com to the actual domain name the application is hosted on.
md5() is a built-in function. It is a encryption technique for securing the user passwords from intruders.
rand( initialValue, finalValue) is a built-in PHP function which takes range as its parameter and generates a random number between them.
mail() is a built-in PHP function for sending emails.
General Syntax:
mail(To, Subject, Content, From)
Video Tutorial: Part 1
Also look at: Email Verification in PHP: Part 2
You can purchase this simple script directly for as less as $1.95 get here.
View Comments
can we give the localhost domain at the save.php file
Sure, you could do that.
Hi SAtish
U r just amazing
I saw ur php video n found ur site and now am ur biggest fan
u r wowwwwwwwww
Thanks a lot
Hi Swati, thanks ..motivates me to keep doing good works :-)
Hi satish, I paid 1.95 USD for script. But it did not come. Could you please send it. or How do I get it?
@hamdi, Will mail you the files. It's actually automated, not sure why you din't get the mail. Will check and fix it too.
Update: Files sent to your email.