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 8099853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:32:49+00:00 2026-06-05T22:32:49+00:00

What I want to implement is a simple login page, if user login successfully,

  • 0

What I want to implement is a simple login page, if user login successfully, then redirect to main page, else remain login page.

I have 1 controller named login, and 1 model named main.
When user click the login button, the login/login_send will be called.

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

class Login extends CI_Controller{

function __construct() {
    parent::__construct();
    $this->load->model('model_login');
}

function index()
{
    if ($this->model_login->is_logged_in())
    {
        redirect('main');
    }
    else
    {
        // load login page
        $data['main'] = 'view_login';
        $data['style'] = 'style_login';
        $this->load->view('template', $data);           
    }
}

function login_send()
{
    $this->form_validation->set_rules('username', 'Username', 'trim|required');
    $this->form_validation->set_rules('password', 'Password', 'trim|required'); 

    if ($this->form_validation->run() == FALSE) 
    {
        $this->index();
    } 
    else 
    {
        if ( $this->model_login->validate_user() )
        {
            $user_session_data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => 1
            );
            $this->session->set_userdata($user_session_data);       
            redirect('main');
        }
        else 
        {
            redirect('login');
        }
    }       
}// end function login_send

function logout() 
{
    if ($this->model_login->is_logged_in())
    {
        $this->session->sess_destroy();
        $this->session->set_userdata(array('username' => '', 'is_logged_in' => 0));
        log_message('debug', 'Some variable was correctly set');
    }
    redirect('login','refresh');
}

}// end class Login
?>

Model_login here is just to help to verify if user is logged in, by check the session data.

<?php
class Model_login extends CI_MOdel{

function _isUserExist($username, $password) 
{   
    $options = array(
        'UserName' => $username,
        'Password' => $password
    );
    $query = $this->db->get_where('userinfo', $options);
    return $query->num_rows() > 0;
}

function validate_user() 
{
    $username = $this->input->post('username');
    $password = $this->input->post('password');

    return ($this->_isUserExist($username, $password));
}

function is_logged_in() 
{
    $is_logged_in = $this->session->userdata('is_logged_in');

    if ( !isset($is_logged_in) || $is_logged_in != 1 ) return FALSE;
    else return TRUE;
}
}// end class model_login
?>

When first time login, and then logout, there is no problem. However, if I login second time, I can not log out. Even the login/logout was called correctly, I also refreshed the page, but the session['is_logged_in'] == 1. Something wrong with my code?

  • 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-06-05T22:32:50+00:00Added an answer on June 5, 2026 at 10:32 pm

    In your application/config/config.php try changing

    $config['sess_time_to_update']  = 300; //This is the default setting in ver 2.1.1
    

    to

    $config['sess_time_to_update']  = 0;
    

    This gave me some problems a few years back

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

Sidebar

Related Questions

I want to implement the user authentication and login page in ASP.NET, I want
All I want is to make a simple user password login. I have put
I want to implement a simple specialized window manager for presentations (not user-controllable) that
I want to create a login page, it can easy implement using Ruby on
I want to implement simple LINQ-to-SQL-like functionality in my .net application. For example i
I want to implement a simple script to do some boring housekeeping on my
I want to implement a simple help form to appear once the application has
I want to implement a simple link that when clicked, deletes the item from
I want to implement something simple like /System/Workflows/Sample Workflow with the small addition of
I want to implement a simple application (modification of sample2) which is showing what

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.