I have to create a web site for my school project and I'm using codeugniter as a framework. My problem is that my code doesn't work. This code is supposed to let the user login to his account. the account exits in the database. Does anyone know how to fix my bug? thank you in advance.
*****Model : ******
<?php
class User_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function check_id($email,$password)
{
$this->db->select('email,mdp');
$this->db->where('email',$email);
$this->db->where('mdp',sha1($password));
$q = $this->db->get('utilisateur');
if($q->num_rows()>0)
{
return true;
}
}
}
?>
*****controler :******
<?php
class Login extends CI_Controller{
function __construct(){
parent::__construct();
}
public function index(){
$this->load->library('form_validation');
$this->load->model('signup_model');
$this->load->library('session');
//Récupérer les données saisies envoyées en POST
$email = $this->input->post('email');
$mdp = $this->input->post('password');
if($this->session->userdata('login') ||$this->session->userdata('logged'))
{
redirection('bibliographie') ;
}
$this->form_validation->set_rules('email','Email','trim|required|xss_clean');
$this->form_validation->set_rules('password','Password','trim|required|xss_clean');
if($this->form_validation->run())
{
if($this->signup_model->check_id($this->input->post('email'), $this->input->post('password')))
{
$data = array('login'=>$this->input->post('email'), 'logged'=>true);
$this->session->set_userdata($data);
redirection('bibliographie/sign_up');
}
else
{
$data['error'] = 'Mauvais identifiants';
$data['titre'] = 'Connexion';
$this->load->view('header',$data);
$this->load->view('sign_up',$data);
$this->load->view('footer');
}
}
else
{
$data['titre'] = 'Connexion';
$this->load->view('header',$data);
$this->load->view('index');
$this->load->view('footer');
}
}
}
?>
Aucun commentaire:
Enregistrer un commentaire