Verify email address using PHP

This is a simple way to verify an email address with PHP.
Sometimes you may need to verify a user’s email address. Today I’m going to show you how to do this with PHP. Our database structure looks like this: The first thing we need to do is connect to the database. Below is the code to do that.
db_connect.php To verify a user’s email, we need to first send them an email with a verification link. This link will look something like this: Let’s break it down. The variable (code=ds9d27d7ddAD790346789FSoBdQzl) in the url is a random string we create for security. The code variable is also stored in the database with the user’s id variable (user=343) in the url to compare both the user’s id and code to the one’s in the database.
 
verify_email.php Once the user clicks the verification link, they will be redirected to the verify.php. We will then check to see if the code in the url matches the one in the database. If it matches, we will delete that row in the database. You can now update your database where you store your user’s info and set email to “verified.”
 
We first get the url variables. Next, we check if the code and user’s id equals the ones we stored in the database. Now we have checked that the code and user’s id equals the ones we stored. If the row count equals 1, then the code and user’s id matched the ones in the database. So in the “if statement”, we delete the row in the verify table where user_id equals the user’s id and the code equals the code from the url. And if the code and user’s id don’t match, we show an error. Here is the whole verify.php code. verify.php Thanks for reading! I hope this is useful for one of your projects.

Tagged with:

View all contributions by

Website:

Related Articles

Advertisement

Stay connected with us

Add us on Google+

Follow us on Facebook

Follow us on Twitter

Get updates via RSS

Get email updates

FEEDBACK0

Leave a Reply

Your email address will not be published. Required fields are marked *