Skip to content

Instantly share code, notes, and snippets.

@gautamk
Created February 4, 2012 15:10
Show Gist options
  • Save gautamk/1738408 to your computer and use it in GitHub Desktop.
Save gautamk/1738408 to your computer and use it in GitHub Desktop.
CodeIgniter Authentication Library , application/libraries/auth.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Auth {
/**
* @author K.Gautam
* @version 0.1
* @todo ability to add configuration.
*/
protected $CI=NULL;
/**
* Get CodeIgniter Instance and
* Load necessary libraries
*/
public function __construct(){
$this->CI =& get_instance();
$this->CI->load->library('session');
}
/**
* Start the session and set session variables.
* @param email address of the user to store on the session
*/
public function login_user($email){
$this->CI->session->set_userdata(array(
'email_address' => $email_address,
'logged_in' => TRUE,
));
}
/**
* Logout user by deleting session information
*/
public function logout_user(){
/*
Logout user by unsetting the data
*/
$this->CI->session->unset_userdata('email_address');
$this->CI->session->unset_userdata('logged_in');
}
/**
* check if the user is logged in
* @return TRUE if data is available and the user is logged in
* else if data is not available it by default returns false
*/
public function is_logged_in(){
return $this->CI->session->userdata("logged_in");
}
}
/* End of file */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment