2

How can I verify an email address with codeigniter? I just went through the manual, I couldn't find this.

With email verification, i mean the exact same verification you see when registering on a community forum.

Thanks in advance!

2 Answers 2

6

Use the Email Class to send the email. The email could contain a link with a "secret key", something random and hash-like, like 5dfg7898ssdf (I made that one up :) ). The link could point to: example.com/verify/user/5dfg7898ssdf Then in a codeigniter controller called "verify", you put this function (just some quick code):

function user($key = NULL)
{
 if($key)
 {
  // Find key in database
  // If it exists, then mark
  // the corresponding user as "activated"
 }
}
5
  • Its what i do all the time. Verifies an email exists by forcing a user to view their email!
    – dotty
    Aug 6, 2010 at 15:32
  • Yep, this is the way I would do it as well. Create a unique verification key for that user, store it in the database as a field in the 'users' table, and create a public method in your "user" controller called "verify($key)" or something like that. Then in your email, link the user to: example.com/user/verify/520592u02492089
    – treeface
    Aug 6, 2010 at 16:46
  • Writing a unique key to the db is the best way to do it, but if for some reason you don't want to use a db field then it would be better to use a salted md5 hash based on the users' email or username rather than having a static secret key like Matthew seemed to suggest.
    – C. E.
    Aug 6, 2010 at 23:18
  • @Calle I didn't mention having a "static" secret key. It would have to be dynamic (it has to verify a specific email, not just any email).
    – Matthew
    Aug 20, 2010 at 14:21
  • ok i have done everything and whats not working here is how will the controller Verify , function users get called. I am able to sent the link to users email and when they click on it the link appears but how will it pass the control to our controller function. I guess we need to do the routing for it. Its simply working like this for me.
    – TaraGurung
    Aug 13, 2015 at 7:43
0
function verify($verificationText=NULL){    

$noRecords = $this->HomeModel->verifyEmailAddress($verificationText);   

if ($noRecords > 0){ 
    $error = array( 'success' => "Email Verified Successfully!");   
}else{ 
    $error = array( 'error' => "Sorry Unable to Verify Your Email!");   
} 
    $data['errormsg'] = $error; 
    $this->load->view('index.php', $data);  
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.