Welcome Guest, Not a member yet? Register   Sign In
Access restrictions to pages using Session.
#4

[eluser]Joseph1982[/eluser]
Hi Friends,

After searching, I created a library for Session Validation. It works like this:

1. After a user login to the site, I added a variable 'logged_in' to Session.

2. Then on the page where it need to check the User Authentication, I just called the Session validation function to make sure that whether the user is logged in or not.

To do this:

Create a new library and save with the name: 'User_authentication.php'

Path to save the Library is: system/application/libraries/User_authentication.php

User_authentication.php file Content is:

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Code Igniter AJAX Class
*
* This class enables you to check User Authentication with the help of Session.
*
* @package        CodeIgniter
* @subpackage    Libraries
* @category    Libraries
* @author        Aniesh
* @link        http://www.no-link-yet.com
*/


class User_authentication
{
    private $obj = null;

    function User_authentication()
    {
        $this->obj =& get_instance();
    }

    function user_validation()
    {

        // Not logged in, then redirect to the Home Page.
        if(!$this->obj->session->userdata('logged_in'))
            redirect('');
    }

}

?>

Then load the Session and this User Authentication library to all pages. For this open the page:

system/application/config/autoload.php


Then search for the $autoload['libraries'] and add the following:

Code:
$autoload['libraries'] = array('User_authentication', 'session');

A sample Controller page, where I need to test the Use Authentications is:

Code:
<?php

class Mysubscription extends Controller
{
    function __construct()
    {
        parent::Controller();

                // This will do the Session Validation task.
        $this->user_authentication->user_validation();
    }

        //  function add-your-functions-here()
      
}

?>


Thank You.


Messages In This Thread
Access restrictions to pages using Session. - by El Forum - 09-16-2008, 05:34 AM
Access restrictions to pages using Session. - by El Forum - 09-16-2008, 07:53 AM
Access restrictions to pages using Session. - by El Forum - 09-16-2008, 11:41 AM
Access restrictions to pages using Session. - by El Forum - 09-18-2008, 03:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB