CodeIgniter Forums
Help on my login controller script ! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Help on my login controller script ! (/thread-6020.html)



Help on my login controller script ! - El Forum - 02-12-2008

[eluser]jigen7[/eluser]
my prob is the cookie how can i get the cookie displaying its value on the next page? i know this is a simple script thx

Code:
<?php

class Admin extends Controller
{
    function Admin()
    {
          parent::Controller();
          $this->load->helper('url');    
          $this->load->helper('form');
          $this->load->helper('cookie');
    }
    
    function index()
    {
          redirect('admin/login');
    }
    
    
    function login()
    {
          $user = @$_POST["username"];
          $passwd = @$_REQUEST["password"];
        
    if($user && $passwd) // if user and password is not empty
    {//1
          $sql = "SELECT * FROM users WHERE username = ? AND password = ?";
         $query = $this->db->query($sql, array($user,$passwd));  

           if ($query->num_rows() > 0)
           {//2
                   foreach ($query->result() as $row)
                   {
                  $user =  $row->username;
                  //echo $row->name;
                  //echo $row->body;
                   }
                
            setcookie('user',$user,0);      # set user id
            redirect('main/show_all');
                  
          
          }//2
          else //Wrong Combination or User not found
          {//3
          $data['prompt'] = "BAD Username & Password Combination";
          
          }//3
    
          $this->load->view('admin_login',$data);
    }//22
    else {   // if user and password is empty  show login page
          $data['prompt'] = "Please Enter User and Password";
          $this->load->view('admin_login',$data);
          
          }
    }//2
  
}//1


?>



Help on my login controller script ! - El Forum - 02-12-2008

[eluser]zwippie[/eluser]
I recommend you take a look at the Session library.