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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:57:37+00:00 2026-06-16T03:57:37+00:00

I have been an avid reader of stackoverflow for a long period of time,

  • 0

I have been an avid reader of stackoverflow for a long period of time, and now its my turn to ask a question.

I followed http://net.tutsplus.com/tutorials/php/easy-authentication-with-codeigniter/ tutorial and have managed to get it to work flawlessly for my self, however I need to expand the system ever so slightly. I need to be able to after the user has been verified to pull additional row fields of the authenticated person and store in session variables, for use in other controllers for sending information back to the database.

For instance I want to have in a sessional variable $f_name, and I need their $username.
I have looked high and low and have found answers but they have only confused me.

My Model:

class admin_model extends CI_Model {
 function __construct( )
 {

 }

 public function verify_user($user_id, $password)
 {
 $q = $this->db->where('user_id', $user_id)
 ->where('password', sha1($password))->limit(1)->get('users');

 if ( $q->num_rows > 0   ){
     return $q->row();
 }
return false;

}

}

My Controller:

class admin extends CI_Controller {

function __construct()
{
parent:: __construct();
session_start();


}

public function index()
{
    if ( isset($_SESSION['user_id'])){
        redirect('welcome');
    }
    $this->load->library('form_validation');
    $this->form_validation->set_rules('user_id', 'User ID', 'required|min_length[8]');
    $this->form_validation->set_rules('password', 'Password', 'required|min_length[4]');

    if ($this->form_validation->run() !==false){
       $this->load->model('admin_model');
      $res = $this
          ->admin_model
          ->verify_user(
          $this->input->post('user_id'),
          $this->input->post('password')
      );
   if ($res !== false) {
    $_SESSION['user_id'] = $this->input->post('user_id');
    redirect ('welcome');
   }






    }

    $this->load->view('login_view');
}

public function logout(){

    session_destroy();
    redirect ('admin');
}
}

Thanks again guys and I look forward to your answers\suggestions

  • 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-16T03:57:39+00:00Added an answer on June 16, 2026 at 3:57 am

    A couple of things:
    – the __construct() function in admin_model needs parent::__construct (or the function could be removed since it’s empty) to inherit the code igniter model constructor.
    – code igniter and PHP sessions are different. You’re using PHP sessions, which means that you’ll have to call session_start() before any output is sent on every page in which you’d like to access the session data. This can also be set for every page in your php.ini by turning on session.autostart

    If you’d like to use code igniter sessions, look here:
    http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

    UPDATE 12/21/2012

    Try setting the session variables from the database row returned:

    $_SESSION['f_name'] = $res->f_name; and $_SESSION['username'] = $res->username; in the same place as where you’re setting the session user id variable. I’m assuming your database fields are mapping to the fields that you’re wanting to use for the f_name and username fields.

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

Sidebar

Related Questions

Have been working on a Tower Defense game for iOS for some time now.
I have been an avid TFS user since 2005 but decided to skip the
Have been working on this question for a couple hours and have come close
I have been using TortoiseSVN for some time and I really like it. I
Have been trying to figure this problem out for a while now and was
have been able to output images from BLOB, however I am now wanting to
Have been trying the whole day long and googled the **** out of the
I have been running nutch crawling commands for the passed 3 weeks and now
Have been doing a codeacademy course http://www.codecademy.com/ru/courses/javascript-lesson-951/0?curriculum_id=4fc3018f74258b0003001f0f#!/exercises/6 - making a vertical sliding pannel. The
I have been an avid fan of lazy loading but yesterday I was talking

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.