开发者

Password reset code example request on parsing url

开发者 https://www.devze.com 2023-03-18 00:31 出处:网络
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

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 th开发者_如何学编程e tokens? I would appreciate a code snippet that demonstrates this. Many thanks in advance.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消