我是新来的Codeigniter。我想创建一个登录&注册页面在我的项目。登录和注册是成功的,但如果我想确认电子邮件,它总是说404未找到如果点击验证链接。这段代码有什么问题?帮我
感谢<?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);
}
}?>
这在你的代码中是一个小问题。
假设md5($to_email)
等于15253545
。在你的邮件中,通过site_url('voter/voter_register/verify').md5($to_email)
这样的邮件发送这个号码。
所以你设置的是:
www.stackoverflow.com/oter/voter_register/verify15253545
没有像verify15253545
这样的函数调用。因为您在URL上缺少/
。所以修改为:
site_url('voter/voter_register/verify/').md5($to_email)
^ Missing / on here
现在您的URL到达验证并将数据传递给$hash
。