Codeigniter电子邮件验证传递参数 [英] Codeigniter email verification pass parameters

查看:122
本文介绍了Codeigniter电子邮件验证传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在注册帐户后执行电子邮件验证。所以在注册帐户后,电子邮件将发送到用户电子邮件进行验证。

I am trying to implement an email verification after registering an account. So after registering an account, an email will be sent to the user email to verify. the email was sent using the email class of codeigniter.

发送电子邮件的代码如下

The code for sending the email is as below

$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('admin@mathplication.com', 'admin');
$this->email->to($user_email); 

$this->email->subject('Registration verification for mathplication');
$this->email->message('
        Thanks for signing up!
            Your account has been created, you can login with the following credentials 
            after you have activated your account by pressing the url below.
            Please click this link to activate your account:
<a href='.base_url('verify').'?email='.$user_email.'&rand='.$user_rand.'>Click Here</a>'); 

$this->email->send();

并在config文件夹的routes.php中

and in the routes.php in the config folder

$route['verify']    = "login_register/view_verify


$ b b

其中view_verify是我的login_register控制器中的函数

in which view_verify is the function in my login_register controller

这里view_verify我将检查我通过的两个参数,电子邮件和生成的随机字符串。

inside this view_verify I will check the two parameters I passed which are the email and the random string generated.

function view_verify($email,$rand)
{
    //$email = $this->input->get('email');
    //$rand = $this->input->get('rand');
    $this->load->database();
    $this->load->model('login_model');
    $result= $this->login_model->email_verification($email,$rand);
    if($result==TRUE)
    {
        $this->load->view('pages/verify');
    }
}

我会得到一个404页面未找到错误不知道如果我的路由与变量是这里的问题或不是或有另一种方式通过url传递参数到控制器。感谢您提供帮助。

I will get a 404 page not found error. Not sure if my routing with the variables is the problem here or not or is there another way of passing parameters through url to the controller. Thanks in advance for the help.

推荐答案

如果您要在网址中使用查询字符串,则需要启用在配置。由于电子邮件地址,可能还会出现 permitted_uri_chars 的问题。

If you are going to be using query strings in the url, you will need to enable that in the config. Possible there might also be issues with permitted_uri_chars because of the email address.

您可以使用用户ID和随机数生成网址:

You could generate the url with the user id and nonce like:

<a href='.base_url('verify').$user_id.'/'.$user_rand.'>Click Here</a>'); 

这应该产生

http://www.example.com/verify/1234/23q23rq2rq24rq34rq34rq34r

然后在路径中:

$route['verify/(:any)']    = "login_register/view_verify/$1";

此时,函数 view_verify 正确的,因为它现在除了你需要调整你的模型,通过用户id而不是通过电子邮件进行查找。

At this point the function view_verify should work correctly exactly as it is now except you will need to adjust your model to do the lookup via user id instead of by email.

这篇关于Codeigniter电子邮件验证传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆