irwan Dwiyanto irwan Dwiyanto - 27 days ago 26
PHP Question

forgot password codeigniter

I tried making forgot password by email using CodeIgniter framework , to send the password change notification email is already working . but after I open the email and click the link to change the password when calling view does not appear .. what's wrong with my script ??

this my controler

public function forgot()
{
$this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|callback_email_check');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('email/email_check');
}
else
{
$email= $this->input->post('email');

$this->load->helper('string', 6);
$rs= random_string('alnum', 12);

$data = array(
'rs' => $rs
);
$this->db->where('email', $email);
$this->db->update('user', $data);

//now we will send an email

$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx@xxx.esy.es ',
'smtp_pass' => 'xxxxx',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);

$this->load->library('email', $config);
//$data = array('tes' => 'tester');
//$message = $this->load->view('v_email',$data,TRUE);
$this->email->set_newline("\r\n");
$email_setting = array('mailtype'=>'html');
$this->email->initialize($email_setting);
$this->email->from('xx@xx.esy.es', 'xxx');
$this->email->to($email);
$this->email->subject('Get your forgotten Password');
$this->email->message($this->load->view('email/email_forgot', $data, TRUE));
if($this->email->send())
{
$data = array ( 'isi' => 'login/vforgot');
$this->load->view('layout/wrapper',$data);
}else
{
$data = array ( 'isi' => 'login/vgagal');
$this->load->view('layout/wrapper',$data);
}


}
}


view email sent

<tr>
<td style="color:#ffffff;font-family:Helvetica,Arial,sans-serif;font-size:15px;font-weight:bold;line-height:100%;padding-top:18px;padding-right:15px;padding-bottom:15px;padding-left:15px" align="center" valign="middle">
<a href="<?php echo site_url('/login/register/get_password/index/'.$rs); ?>"style="color:#ffffff;text-decoration:none" target="_blank">Reset Password</a>
</td>
</tr>


controllers get_password

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Get_password extends CI_Controller
{
public function index($rs=FALSE)
{


$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[7]|max_length[20]|matches[passconf]|md5');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');

if ($this->form_validation->run() == FALSE)
{
echo form_open();
$this->load->view('email/gp_form');

}
else
{
$query=$this->db->get_where('user', array('rs' => $rs), 1);

if ($query->num_rows() == 0)
{
show_error('Sorry!!! Invalid Request!');
}
else
{
$data = array(
'password' => $this->input->post('password'),
'rs' => ''
);

$where=$this->db->where('rs', $rs);

$where->update('user',$data);

echo "Congratulations!";
}

}

}

}


views gp_form

<?php echo validation_errors();

echo "Password :".form_password('password', '');
echo "Password Confirmation :".form_password('passconf', '');
echo form_submit('submit', 'Submit');

?>


and this result klik form email


http://xxxxxx.com/login/register/get_password/index/cfCZm29TPrT6

404 Page Not Found

The page you requested was not found.

Answer

Whats the full URL you are passing? If you getting a 404 it's because your page is missing.

Have you set up friendly urls in your .htaccess? if not then the URL will be

http://example.com/index.php/login/register/get_password/index/cfCZm29TPrT6
Comments