[eluser]bubbafoley[/eluser]
[quote author="InsiteFX" date="1298704991"]Try this:
Code:
/*
* Auth class constructor
*/
function __construct()
{
parent::__construct();
// Create an instance of CI resources
$this->CI =& get_instance();
}
InsiteFX[/quote]
This library has no parent :coolsmile:
It works for me. Are you sure you're getting a valid database result?
Here's my code.
application/libraries/auth.php:
Code:
<?php
class Auth
{
public $CI;
/*
* Auth class constructor
*/
function __construct()
{
// Create an instance of CI resources
$this->CI =& get_instance();
}
/*
* Takes the submitted information and registers the visitor
*
* @access public
* @param array
* @return array
*/
function register_visitor($visitor_details)
{
}
/*
* Takes submitted credentials and looks for a valid match in the database
*
* @access public
* @param1 string
* @param2 string
* @return boolean
*/
function validate_visitor($username, $password)
{
// Now set the session information
$user_session_information = array(
'username' => $username,
'logged_in' => TRUE
);
$this->CI->session->set_userdata($user_session_information);
return true;
}
/*
* Determines if the user is authenticated
*
* @access public
* @return boolean
*/
function is_authenticated()
{
if ($this->CI->session->userdata('logged_in') == TRUE)
{
return true;
}
return false;
}
}
tip: if you return inside an "if()" then you don't need an else. just continue on like normal.
application/controllers/welcome.php
Code:
<?php
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('session');
}
function index()
{
$this->load->library('auth');
$this->auth->validate_visitor('foo', 'bar');
if($this->auth->is_authenticated())
{
echo $this->session->userdata('username');
}
}
}
Output: