How to implement PHP, e-mail authentication to activate the user

Source: Internet
Author: User
How does PHP implement, e-mail authentication activates the user?
means, how to achieve, with e-mail implementation, e-mail to activate the user?
My program has already used an e-mail class!
Used to retrieve the password!
But I want to register, in the addition of email to verify the user to activate the user!
You should know that many programs are carried, the program will be executed automatically generated URL address, sent to the user's mail!
Users click on the URL link, the user will be activated!
But I want to know how to achieve it?
is automatically generated URL address that step will not, there is no verification, but there is no source code can not know how to use!
Who can tell me how to implement the auto-generated URL address?


It is better to give an example code, or provide open source program with what I say function!

Thank you..

------Solution--------------------
Instance code currently does not have, open source program has you say that the function of many, such as uchome,discuz or something.


In fact the principle is very simple, you say automatically generate URL that step does not, first URL is divided into two parts:
The first part is a verification address with a parameter that identifies the user ID, for example: http://www.xxx.com/active.php?uid=1
The second part is actually a string to verify, for example: authcode=asdad1f323ff43f
Together, it's http://www.xxx.com/active.php?uid=1&authcode=asdad1f323ff43f.

The first part is your decision, active.php is the one you wrote the verification script, so you can know the address?
Is the second part a randomly generated string? You can use this formula to generate this string using: MD5 (own domain name + timestamp + authenticated username). Of course you can define how to combine this string, just make sure they don't have a regular guess, and don't repeat it.
It's simple, isn't it?


As for when to generate and when to validate, you can design this:
You can add two fields to the user table: 1 (bool isActive) If the user is activated, the default is False. 2 (string authcode) temporary activation code.
When the user registers, or clicks the Activate button, executes one of your scripts:
1 Generate the activation code, that is the method I said above.
2 Use this activation code to store the activation code in the Authcode field of the user table.
3 Send your full activation address to the user's mailbox by email
4 your script, when the request is received, two parameters are removed to the user table in the search uid=1 the user's authcode is equal to the database, if equal, the validation passes, and empties the Update IsActive field is true,authcode fields update to empty.


That's it, of course, to avoid generating duplicate verification codes and other people's guesses, you can set a time-out for Authcode. There are a number of ways that you can add a timestamp to the user table, with the current timestamp + a valid timestamp period, such as time () +3600, which is the one-hour timeout, which, when verified, can be compared to whether it is within this timestamp at the same time. This kind of stuff, you can also put in the cache or in memory. That would be better.


You may also need to make a switch, maybe you want the new registered users to need mail activation today, and tomorrow you may not want to. Used to control whether mail activation is required. First, if this value is true, all registered users are isactive false, otherwise they are true.
------Solution--------------------
In addition to thinking about sending mail to customers


Also consider that the mailbox does not receive the situation. Because there's no guarantee of a 100% arrival rate.

So, also to provide a mailbox, let customers send a mail to the designated mailbox

The program reads the mailing list, if there is a mail from a mailbox, and a registered user uses the mailbox, verify that a
  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.