[eluser]djalilk[/eluser]
Hi everybody,
I am new to codeIgniter and trying to create a login system, and didn't find any solution to my problem
: when I try to login, if the username or the password is wrong the flashdata message is displayed only if I submit my form twice.
here is the controller function:
Code:
function verify(){
if ($this-> input->post('username')){
$user = $this->input->post('username');
$password = $this->input->post('password');
$this->Admin->verifyAdmin($user,$password);
if(isset($_SESSION['userid'])) {
if($_SESSION['userid'] > 0){
redirect('/admin/dashboard/','refresh');
}
}
}
$data['main'] = 'admin';
$data['title'] = "Foctus | Admin Login";
$data['categories'] = $this->Category->getActiveCategories();
$this->load->vars($data);
$this->load->view('template',$data);
}
the model :
Code:
function verifyAdmin($user, $password){
$data= array();
$this->db->where('username', $user);
$this->db->where('password', $password);
$this->db->where('status', 'active');
$this->db->limit(1);
$Q = $this->db->get('admins');
if ($Q->num_rows() > 0){
$row = $Q->row_array();
$_SESSION['userid'] = $row['id'];
$_SESSION['username'] = $row['username'];
}
else{
$this->session->set_flashdata('error', 'Sorry, your username or password is incorrect!');
}
}
And the view :
Code:
<div id="pleft">
<h2> Please login to Access the Dashboard </h2>
<?php
if($this->session->flashdata('error')) {
echo '<div class="message"> ';
echo '<p>'.$this->session->flashdata('error').'</p>';
echo'</div>';
}
?>
<?php
$userData = array('name'=>'username','id'=>'u','size'=>15);
$passwordData = array('name'=>'password','id'=>'p','size'=>15);
echo form_open("/welcome/verify/");
echo "<p> <label for='u'> Username </label> <br/> ";
echo form_input($userData)." </p> ";
echo "<p> <label for='p'> Password </label> <br/> ";
echo form_password($passwordData)." </p> ";
echo form_submit('submit','login');
echo form_close();
?>
</div>
Please help me
Thank you.