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

  • Home
  • SEARCH
  • 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 4015878
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:40:21+00:00 2026-05-20T09:40:21+00:00

Hey there, i want to store some session info from a database query, upon

  • 0

Hey there, i want to store some session info from a database query, upon log in,
but for some reason it isnt letting me set the session userdata!?!

Can anyone shed any light as to why?

Controller:

function validate_login(){
$this->load->library('form_validation');
$this->form_validation->set_rules('email_address', "Email address","required|valid_email");
$this->form_validation->set_rules('password', "Password", "trim|required|min_length[6]|max_length[32]");

if($this->form_validation->run() == FALSE){

  $this->login();

} else {

  $email_address = $this->input->post('email_address');
  $password = md5($this->input->post('password'));
  $prev_page = $this->input->post('referrer');

  $found_user = $this->account_model->validate_user($email_address, $password); // calls to function of the same name in the model, returns array.

  if($found_user){

    $session_data = array(
      'user_id' => $found_user->user_id,
      'is_logged_in' => TRUE
    );

    // Debug code

      if($this->session->set_userdata($session_data)){
        echo "success session";
        } else {
        echo "failure session";
      }

  } else {
    //Debug code
    echo 'no user found';
  }
}
}

Model:

  function validate_user($email_address, $password){

$this->db->where('email_address', $email_address);
$this->db->where('password', $password);
$query = $this->db->get('user');

if($query->num_rows() == 1){

   foreach($query->result() as $row){
        $data = $row;
      }
      return $data;

} else {
    return FALSE;
}

}

  • 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-20T09:40:21+00:00Added an answer on May 20, 2026 at 9:40 am

    I’m posting this as another answer just so I can paste this code snippet. I think everything is working as it should be. The set_userdata function returns void, so you don’t need to encapsulate it in an if statement.

    Instead of the following code:

    if($this->session->set_userdata($session_data)){
        echo "success session";
        } else {
        echo "failure session";
      }
    

    It should just be:

    this->session->set_userdata($session_data);
    

    You can use this function to add new data or changing existing data in the session; it doesn’t matter if there’s already data in it.

    Another answer:

    Are you loading the session library? Being a commonly used library I would recommend loading it in the autoload config file, like so:

    $autoload['libraries'] = array('session', 'other libraries etc');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey there i want to change some css attributes from javascript but i cant
Hey there! now first of all some might want to shout that there are
hey there, Im having problems displaying my results in this program but the program
hey there i am having problem i have List<List<memoryCard>> that i want to show
Hey there I have 2 tables with each multiple columns and i want to
Hey there, I've started to play around with Fluent NHibernate and now I want
Hey there, I want to evaluate a mathematical function (user-defined) which returns several values
hey there. I'm developing a website and i want to have a password recovery
hey there, i have quite some issues with the mode rewrite here is what
Hey there, I want to simulate the press of iPhone home button and power/standby

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.