CodeIgniter Laravel PHP Example Javascript jQuery MORE
Need a Website Or Web Application Or Any Help In Code As Per Your Budget, Contact Us: +91 9437911966 (Whatsapp)

How to change password in CodeIgniter framework


In this example we are going to show you How to send forgot password in CodeIgniter framework PHP.

Here we using 2 files for insert data in MySQL:

  • Forms.php Path: codeIgniter\application\controllers\Forms.php
  • forgot_pass.php Path: codeIgniter\application\views\change_pass.php

Forms.php (Controller)

<?php 
class Forms extends CI_Controller 
{
	public function __construct()
	{
		/*call CodeIgniter's default Constructor*/
		parent::__construct();
		/*load database libray manually*/
		$this->load->database();
		$this->load->library('session');
		/*load Model*/
		$this->load->helper('url');
		$this->load->model('Hello_model');
	}
	
   public function forgot_pass()
	{
		if($this->input->post('forgot_pass'))
		{
			$email=$this->input->post('email');
			$que=$this->db->query("select pass,email from user_login where email='$email'");
			$row=$que->row();
			$user_email=$row->email;
			if((!strcmp($email, $user_email))){
			$pass=$row->pass;
				/*Mail Code*/
				$to = $user_email;
				$subject = "Password";
				$txt = "Your password is $pass .";
				$headers = "From: password@example.com" . "\r\n" .
				"CC: ifany@example.com";

				mail($to,$subject,$txt,$headers);
				}
			else{
			$data['error']="

Invalid Email ID !

"; } } $this->load->view('forgot_pass',@$data); } } ?>

forgot_pass.php (View)

<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>

</head>
<body>

<div id="main">
<div id="login">
<?php echo @$error; ?>
<h2>Forgot Password</h2>
<br>
<form method="post" action=''>
		<label>Email ID :</label>
		<input type="password" name="email" id="name" placeholder="Email ID"/><br /><br />
	    <input type="submit" value="login" name="forgot_pass"/><br />
</form>
</div>
</div>
</body>
</html>
 

Run the program on your browser with URL:

http://localhost/codeIgniter/index.php/Forms/forgot_pass

Here codeIgniter is my folder name. Put your folder name instead of codeIgniter.Rest of things are same.