我是 Codeigniter 的新人。我想创建一个登录&我的项目中的注册页面。登录和注册成功但如果我想确认电子邮件,如果单击验证链接,则总是说 404 not found 。这段代码有什么问题。帮帮我
由于
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Voter_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//get the username & password from tbl_usrs
function get_user($username, $password)
{
$sql = "select * from user where username = '" . $username . "' and password = '" . $password . "' and status = '1'";
$query = $this->db->query($sql);
return $query->num_rows();
}
//insert into user table
function insertUser($data)
{
return $this->db->insert('user', $data);
}
//send verification email to user's email id
function sendEmail($to_email)
{
$from_email = ''; //change this to yours
$subject = 'Aktivasi Akun';
$message = 'Dear'. $username .'<br /><br />Please click on the below activation link to verify your email address.<br /><br />
'. site_url('voter/voter_register/verify') . md5($to_email) . '<br /><br /><br />Thanks<br />Admin, Gus bala';
//configure email settings
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com'; //smtp host name
$config['smtp_port'] = '465'; //smtp port number
$config['smtp_user'] = $from_email;
$config['smtp_pass'] = ''; //$from_email password
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes
$this->email->initialize($config);
//send mail
$this->email->from($from_email, 'Admin Evoting');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
return $this->email->send();
}
//activate user account
function verifyEmailID($key)
{
$this->load->database();
$data = array('status' => 1);
$this->db->where(md5('email'), $key);
$this->db->update('user', $data);
}
}?>
答案 0 :(得分:0)
这是您的代码的小问题
假设您的md5($to_email)
等于15253545
。并且在您的邮件中通过邮件发送此号码,如site_url('voter/voter_register/verify').md5($to_email)
所以你设置的是
www.stackoverflow.com/oter/voter_register/verify15253545
没有像verify15253545
这样的函数调用。 Cz您在URL上缺少/
。所以修复是
site_url('voter/voter_register/verify/').md5($to_email)
^ Missing / on here
现在,您的网址已到达验证并将数据传递到$hash