I'm developing with Codeigniter and working on password reset using a similar model to Amazon: The user clicks on a link that I email and this leads into the controller that launches the appropriate view. However I need to attach some tokens to the end of the uri for security reasons. Where do I intercept the uri within Codeigniter so as to remove the tokens? I would appreciate a code snippet that demonstrates this. Many thanks in advance.
1 Answer
You can send an URL like www.yousite.com/index.php/password/reset/116wef4wef4325w6e4
In your controller password.php you have:
class Password extends CI_Controller {
function reset($token)
{
if(isset($token) AND $token != '')
{
$retrived_token = $token; //it's automatically passed by CI to this method.
//It would output 116wef4wef4325w6e4
//you may do some validation of it through a model here.
//ex. if($this->mymodel->validate_token($retrieved_token)
//{ do something } else { }
}
}
}
You didnt provide any info on how your app is structured, so I just guessed you might have a controller just for dealing with passwords. If it's not the case, you can have a 'password' method inside the parent controller, which in turn takes 2 parameters, in this case 'reset' and the 'token'. Or you could use a custom route maybe. If you provide this informations I might help updating my code suggestion.
1 Comment
Damien Pirsy
@Usplitu John Glad to have helped! And if you found that it solved your problem, you could mark the answer as 'accepted' (using the thick mark). Thank you, and if you have any problems just ask