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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:24:04+00:00 2026-05-29T13:24:04+00:00

Here it is my code: <?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access

  • 0

Here it is my code:

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

class Login extends CI_Controller 
{
    public function __construct() 
    {
        parent::__construct();
        $this->load->database(); /* This function it's used to connect to database */
        $this->load->model('User','user'); /* This call the model to retrieve data from db */
    }

    public function index()
    {
        if(!file_exists('application/views/_login.php'))
        {
            show_404();
        }

        $this->load->library('form_validation');

        $this->form_validation->set_error_delimiters('<h4 style="text-align:center;">','</h4>');

        $this->form_validation->set_rules('username','username','trim|required|xss_clean');
        $this->form_validation->set_rules('password','password','trim|required|xss_clean|callback_pass_check');

        if($this->form_validation->run() == FALSE)
        {
            $data['title'] = "User Access";
            $data['author'] = "Salvatore Mazzarino";

            $this->load->view('templates/_header',$data);
            $this->load->view('_login',$data);
            $this->load->view('templates/_footer',$data);
        }
        else 
        {   
            redirect('home', 'refresh');            
        }
    }

    public function pass_check($pass)
    {
        $result = $this->user->find_user($this->input->post('username'),$pass);

        if($result == 1)
        {
            $session_array = array();
            foreach ($result as $row) 
            {
                $session_array = array('id'=> $row->id,'username'=> $row->username); /* Create a session passing user data */

                $this->session->set_userdata('logged_in',$session_array);
            }
            return TRUE;
        }
        else
        {
            $this->form_validation->set_message('pass_check',"Invalid username or password!</br>Try again, please!");
            return FALSE;
        }
    }
}

Here it is the line

$this->session->set_userdata('logged_in',$session_array);

that cause the error:

PHP Fatal error:  Call to a member function set_userdata() on a non-object

Someone could say me the reason?

  • 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-29T13:24:05+00:00Added an answer on May 29, 2026 at 1:24 pm

    Make sure the session library is loaded.

    You can add it in application/config/autoload.php to be loaded automatically.

    http://ellislab.com/codeigniter/user_guide/libraries/sessions.html

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

Sidebar

Related Questions

Here's the code: <?php class Order extends Zend_Db_Table_Abstract { protected $_name = 'orders'; protected
Here's the code: <?php class Order extends Zend_Db_Table_Abstract { protected $_name = 'orders'; protected
For example, my goal is to test the code given here: PHP script that
i have a controller like this one : <?php if( ! defined('BASEPATH')) exit ('No
Here is my PHP code.. $input = zergling-light $output = str_replace('-', ' (', $input).);
Here's my code for registerFormOne.php : <html> <head> <title>Registration Form - 1 of 2</title>
here is my mysql and php code layout: I have 3 tables tableA stores
So I have some PHP code that looks like: $message = 'Here is the
Here is the code I dont know whats wrong with it. <?php //Logout code
here is the code <php? $id1 =1; $id2 = module 1 loaded; echo $var1=$id1,$var2=$id2;

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.