Search code examples
phpmysqlgetactivationuser-registration

How to implement an activate.php script?


I am trying to create a script that verifies (activates) the users account from a variable that is sent to them in their registration email.

the url will look like

activate.php?confirm=h47H35gGdh7G6dh3j

and I will $_GET["confirm"] and check it against the database, but I don't know how to catch all of the errors that I could encounter for example:

  • User already activated
  • activation code wrong
  • no activation code at all etc

How can I do this?


Solution

  • I have managed to answer it myself.

    Basically I pulled the value from the $_GET array and used that value to see if it exists within the database, if it did, then I used another if statement to see whether that user's status was already set to 'active', if so, it would not do anything but if the account wasn't active then it would set it to active and confirm this.