Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7183061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:54:11+00:00 2026-05-28T17:54:11+00:00

I am a newbie in codeigniter. I am using an an login form to

  • 0

I am a newbie in codeigniter. I am using an an login form to login as an admin. When the admin logs in with the correct user name and password s/he is directed to the home page with a session variable.and then if he clicks the log out button the session is supposed to be destroyed and redirect the user to log in page i.e log in form page.

The 1st controller is admin:

<?php
class Admin extends CI_Controller
{
    function index()
    {
        $data['main_content'] = 'admin/log_in';
        $this -> load -> view('includes/admin/admin_template', $data);
    }
    function log_in()
    {
        $this->load->model('admin_model');
        $query = $this -> admin_model -> validate();
        if ($query)// if the user's credentials validated...
        {
            $data = array('user_name' => $this -> input -> post('user_name'), 'is_logged_in' => true);
            $this -> session -> set_userdata($data);
            redirect('admin/home/admin_home');
        } else// incorrect username or password
        {
            $this -> index();
        }
    }
    function log_out()
    {
        $this->session->sess_destroy();
        redirect('/admin/admin','refresh');
    }
}

The second controller is the home controller:

<?php
class Home extends CI_Controller
{
    function __construct()
    {
        parent:: __construct();
        $this->is_logged_in();
    }
    function is_logged_in() 
    {
        $is_logged_in = $this -> session -> userdata('is_logged_in');
        if (!isset($is_logged_in) || $is_logged_in != true)
        {
            $this -> load -> view('admin/forbidden');
        }
    }
    function admin_home()
    {
        $data['main_content'] = 'home_view';
        $this->load->view('admin/home_view');
    }
}

The model is admin_model:

<?php
class Admin_model extends CI_Model
{
    function __construct()
    {
        parent:: __construct();
    }
    function validate()
    {
            $this->db->where('user_name',$this->input->post('user_name'));
            $this->db->where('password', $this->input->post('password'));
            $query = $this->db->get('user');
            if($query->num_rows==1)
            {
                return true;
            }
    }
}

Now, it supposed the user to logout and destroy the session, but if I click the back button of my browser I can get page back which was supposed not to be and the session is not destroyed.
please tell me what I am doing wrong here. I am using codeigniter 2.1.0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:54:12+00:00Added an answer on May 28, 2026 at 5:54 pm

    after going through all the troubles and searching in various places i have finally found a proper solution to this question.the problem arrived because the browser was showing the cached pages.it was not the session that was creating the problem and it was working properly.
    here is the solution:
    in the home controller adding a function to clear the cache and calling it in the constructor function does the trick 🙂
    here is the home controller with the solution:

    <?php
    class Home extends CI_Controller
    {
        function __construct()
        {
            parent:: __construct();
            $this->is_logged_in();
            $this->clear_cache();
        }
        function is_logged_in() 
        {
    
            if (!$this->session->userdata('is_logged_in'))
            {
                redirect('/admin/admin');
            }
        }
        function clear_cache()
        {
            $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
            $this->output->set_header("Pragma: no-cache");
        }
        function admin_home()
        {
            $data['main_content'] = 'home_view';
            $this->load->view('admin/home_view');
        }
    }
    

    now thanks goes to this link ” logout feature in code igniter “,here is where i have found the solution and it works perfectly 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie here. I'm using codeigniter and mysql How can I dynamically (number of names
am newbie to jquery..I have a three steps registration form in which the user
i am newbie in CodeIgniter...and i am trying to do form validation for array
Newbie question since I'm not up to speed using maven at all. I'm trying
Newbie question. Given the following html. <div id=mycontainer1 class=container> <input type=text class=name/> <input type=text
I am a newbie in CodeIgniter. And would like to know how am I
What is the best way to check session from a view in CodeIgniter, it
I am newbie. I have Windows XP and use the CodeIgniter framework. I wanted
I am a newbie to drupal, and have used cakephp and codeigniter frameworks earlier.
Newbie here programming my first app (having made several tutorial apps). I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.