Php implementation, E-mail authentication to activate users
Source: Internet
Author: User
How does php implement E-mail authentication to activate users? It means how to implement it, use E-mail to implement it, and send an email to activate the user? My program has used an e-mail class! Used to retrieve the password! But I want to activate the user only when I add an email to verify the user! You should know that many programs are included. during registration, the program will automatically generate a URL address and send it to the user's email! The user clicks the URL link php. how does one implement the E-mail verification to activate the user?
It means how to implement it, use E-mail to implement it, and send an email to activate the user?
My program has used an e-mail class!
Used to retrieve the password!
But I want to activate the user only when I add an email to verify the user!
You should know that many programs are included. during registration, the program will automatically generate a URL address and send it to the user's email!
The user clicks the URL link to activate the user!
But I want to know how to implement it?
This is the step where the URL address is automatically generated. it will not be used for verification, but you do not know if you can use the source code!
Who can tell me how to automatically generate URL addresses?
It is best to provide an instance code or an open-source program with the functions I mentioned!
Thank you ..
------ Solution --------------------
The instance code is not available at present. open-source programs have many such functions as uchome and discuz.
In fact, the principle is very simple. you said that the URL will not be generated automatically. First, the URL is divided into two parts:
The first part is a parameter that verifies the address and carries a user ID, such as: http://www.xxx.com/active.php? Uid = 1
The second part is actually a string used for verification, for example: authcode = asdad1f323ff43f
Together is http://www.xxx.com/active.php? Uid = 1 & authcode = asdad1f323ff43f
The first part is determined by you. active. php is the verification script you wrote, so you can know the address?
Isn't the second part a random string? You can use the formula md5 (your domain name + timestamp + verified username) to generate this string. Of course, you can define how to combine this string by yourself, as long as you make sure they are not regularly guessed, do not repeat it.
Is it easy?
You can design it as follows:
You can add two fields in the user table: 1 (bool isActive) whether the user is activated. the default value is false. 2 (string authcode) temporary activation code.
After the user registers, or click the Activate button, it will execute one of your scripts:
1. Generate the activation code, which is the method I mentioned above.
2. store the activation code to the authcode field of the user table.
3. send your complete activation address to your email address.
4. when your script receives the request, it will remove the two parameters to the user table to search for whether the authcode of the user with uid = 1 is equal to that in the database. if they are equal, the verification passes, the update isActive field is cleared to true, and the authcode field is updated to null.
That's it. of course, to avoid generating duplicate verification codes and others' guesses, you can set a timeout value for authcode. There are many ways to do this. you can add a field to the user table as a timestamp and use the current timestamp + valid timestamp period, such as time () + 3600, this is the time-out period of one hour. during verification, you can check whether it is within the timestamp. You can also store such things in cache or memory. This will be even better.
You may need to make another switch. maybe you want to activate emails for all newly registered users today, and tomorrow you may not want. Used to control whether Email activation is required. If the value is true, the isActive values of all registered users are false; otherwise, the values are true.
------ Solution --------------------
Besides sending emails to customers
You must also consider the situations where the mailbox cannot be received. Because the arrival rate of 100% cannot be guaranteed
Therefore, you also need to provide an email so that the customer can send an email to the specified email address.
The program reads the email list. if there is an email from mailbox A and A registered user uses the email, the application passes the verification
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.