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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:57:28+00:00 2026-05-27T11:57:28+00:00

I created a simple log in system, and i used CI Sessions for holding

  • 0

I created a simple log in system, and i used CI Sessions for holding some values.
But CI sessions did’t work as expected, it does not retrieve any value.
I tried to track the problem, and i figured out something:
Whenever i refresh the page, a new session is created!
And only 1 session hold my custom variables(is_logged, username).
Other sessions just hold default data.
I tried holding the sessions in a database, and still the same problem.
Is it my encryption key?
I just used bunch of random letters, because i can’t keep it empty.
This is the controller I tested my sessions on.
Note:
I’m using some echo‘s here, just for testing.
Note2:
I can retrive session variables only if i call it on the same page.

 <?php

class site extends CI_Controller {

    function index() {
        if (!$this->session->userdata('is_logged')) {
            $data['main_content'] = 'site_view';
            $this->load->view('template/all_templates', $data);
        } else {
            echo 'you\'re logged already';
        }
    }

    function login() {
        if (!$this->session->userdata('is_logged')) {
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            if ($username && $password) {
                if ($this->site_model->validate($username, $password)) {
                    $user_data = array('username' => $username, 'is_logged' => TRUE);
                    $this->session->set_userdata($user_data);
                    echo 'you successfully log in.';
                    redirect('site/index', 'refresh');
                } else {
                    echo 'cannot login';
                }
            } else {
                echo 'username and/or password not set';
            }
        } else {
            echo 'you\'re logged in already!';
        }
    }
}
?>

Note:
This question is related to this one

Edit1:
I logged in few times, sometimes with no errors.
After few refreshes/log ins, see sesssion database:

02d6e3521046ffe7df36b07e88624a60    127.0.0.1   Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (K  1323803371  
66a9cf3d6b7e0521dcc7e5bd3d5d4ad1    127.0.0.1   Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (K  1323803380  
923a78db029ee3e3ae4bf9e09873fcae    127.0.0.1   Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (K  1323803366  a:3:{s:9:"user_data";s:0:"";s:8:"username";s:4:"aziz";s:9:"is_logged";b:1;}
99ac075792b7818aadac60d00ca46947    127.0.0.1   Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (K  1323803367  
bbe10f3338226c8d83b0ae58d1ca5149    127.0.0.1   Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (K  1323803343  a:3:{s:9:"user_data";s:0:"";s:8:"username";s:4:"aziz";s:9:"is_logged";b:1;}
ed6a22ae1d2fd21b6ef66668c2078a11    127.0.0.1   Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (K  1323803375  
feb5806176dc8a4f7ed8f30763f65f8b    127.0.0.1   Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (K  1323803380  a:3:{s:9:"user_data";s:0:"";s:8:"username";s:4:"aziz";s:9:"is_logged";b:1;}  

As you may notice, some results with user data.

my validate function :

function validate($username, $password) {

    $this->db->where('username', $username);
    $this->db->where('password', $password);
    $query = $this->db->get('users');
    if ($query->num_rows() == 1) {
        return true;
    } else {
        return false;
    }
}  

Note:
I tested in FF & Chrome.

  • 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-27T11:57:29+00:00Added an answer on May 27, 2026 at 11:57 am

    Aziz a couple of months ago I suffered a lot of troubles with the original CI session library (included what you mention). Finally I arrived to this replacement that use native PHP session. It works!
    Believe me, in the middle of a project, I did not stop to wonder why. Just works.

    Here it is: Codeigniter’s Native session (there is a download link at the bottom)

    BUT, due that it is an old library you MUST made some hacks. You can check those simple hacks in the library’s forum

    Just drop this file in codeigniter’s library directory. And let’s talk about forward compatibility after, I mean it! 🙂

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

Sidebar

Related Questions

I am trying to create a simple log in system that uses ajax but
I am new to Repository concept and get some questions. I have created simple
I created a simple detail edit form earlier, and decided to data bind some
I created some temp files with a custom task in the system's default temp
Unfortunately, my question is not as simple as keeping track of two windows created
I've created a simple HttpModule to log the uses of my existing webservice. There's
I am attempting to create a simple program that will keep a text log
Could someone help me on this, I have created simple web services using axis2
How to manually create Friendly URLs? (PHP) So I have created simple php file
I created a simple PHP site for a friend last year. I went to

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.