• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
prblem in reading Cookie value

#7
[eluser]ahmadalyan[/eluser]
sorry the function that i use to log user in and out are

Code:
function login($email, $password,$is_remember_me_checked)
{
  // get codeigniter instance
  $CI =& get_instance();
  
  // where variable
  $where = "((".$this->auth_config['user_name']."='".$email."' AND ".$this->auth_config['user_pwd']."='".$password."') OR (".$this->auth_config['user_email']."='".$email."' AND ".$this->auth_config['user_pwd']."='".$password."')) ";
  
  // select segment
  $CI->db->select($this->auth_config['user_id']);
  $CI->db->select($this->auth_config['user_name']);
  $CI->db->select($this->auth_config['user_pwd']);
  $CI->db->select($this->auth_config['user_email']);
  
  // where segment
  $CI->db->where($where);
  
  // get data
  $query = $CI->db->get($this->auth_config['user_table'],1);
  //echo $query->num_rows();

  if($query->num_rows() !== 1)
  {
   /* their username and password combination
   * were not found in the databse */
   return false;
  }
  else
  {
   // reading variable
   $row = $query->row_array();
  
   $user_id = $row[$this->auth_config['user_id']];
   $user_name = $row[$this->auth_config['user_name']];
   $user_email = $row[$this->auth_config['user_email']];
  
   // build variable for session
   $user_agent = $CI->input->user_agent();
   $user_guid = crypt(($this->guid()),'[email protected]#$1234');
  
   //update the last login time
   $last_login = date("Y-m-d H-i-s");
   $ip_address = $CI->input->ip_address();
  
   // check if ip address valid
   if(!$CI->input->valid_ip($ip_address))
   {
    return false;
   }
  
   $data = array(
    $this->auth_config['user_id'] => $user_id ,
    $this->auth_config['user_guid'] => $user_guid ,
    $this->auth_config['ip_address'] => $ip_address ,
    $this->auth_config['user_agent'] => $user_agent ,
    $this->auth_config['last_login'] => $last_login
   );
  
   // do insert to login activity
   $CI->db->insert($this->auth_config['login_table'], $data);
  
   // set cookie if it check
   if($is_remember_me_checked === true)
   {
    $CI->input->set_cookie($this->auth_config['user_id'],$user_id );
    $CI->input->set_cookie($this->auth_config['user_guid'],$user_guid );
    $CI->input->set_cookie($this->auth_config['ip_address'],$ip_address );
    $CI->input->set_cookie($this->auth_config['user_agent'],$user_agent );
    $CI->input->set_cookie($this->auth_config['last_login'],$last_login );
   }
  
   //store user id in the session
   $_SESSION["user_id"] = $user_id;
   $_SESSION["user_name"] = $user_name;
   $_SESSION["user_email"] = $user_email;
   $_SESSION["ip_address"] = $ip_address;
   $_SESSION["user_agent"] = $user_agent;
   $_SESSION["last_login"] = $last_login;
   $_SESSION["user_guid"] = $user_guid;
   echo 'hi';
   return true;
  }
}

function logout()
{
  session_destroy();
  unset($_SESSION);
  
}


public function guid()
{
  return sprintf('xx-x-x-x-xxx',

    // 32 bits for "time_low"
    mt_rand(0, 0xffff), mt_rand(0, 0xffff),
  
    // 16 bits for "time_mid"
    mt_rand(0, 0xffff),
  
    // 16 bits for "time_hi_and_version",
    // four most significant bits holds version number 4
    mt_rand(0, 0x0fff) | 0x4000,
  
    // 16 bits, 8 bits for "clk_seq_hi_res",
    // 8 bits for "clk_seq_low",
    // two most significant bits holds zero and one for variant DCE1.1
    mt_rand(0, 0x3fff) | 0x8000,
  
    // 48 bits for "node"
    mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
   );
}

and when i want to check if the user is log in i used

Code:
if(!$this->auth->is_logged_in())
{
  $data["language"] = $this->language_dic;
  $data['title']='Admin Login Page';
    
  echo Modules::run('admin_login/index',$data);
  return;
}


Messages In This Thread
prblem in reading Cookie value - by El Forum - 01-04-2013, 01:02 PM
prblem in reading Cookie value - by El Forum - 01-05-2013, 11:01 AM
prblem in reading Cookie value - by El Forum - 01-05-2013, 11:04 AM
prblem in reading Cookie value - by El Forum - 01-07-2013, 11:49 AM
prblem in reading Cookie value - by El Forum - 01-07-2013, 01:14 PM
prblem in reading Cookie value - by El Forum - 01-08-2013, 01:35 PM
prblem in reading Cookie value - by El Forum - 01-08-2013, 01:39 PM
prblem in reading Cookie value - by El Forum - 01-08-2013, 04:29 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.