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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:58:46+00:00 2026-06-14T05:58:46+00:00

I have a model: <?php class Loginfunctionmodel extends CI_Model{ function __construct() { // Call

  • 0

I have a model:

<?php

class Loginfunctionmodel extends CI_Model{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();

    }

    # check_if_loggedin() below checks if user has session w/ loggedIn=1, then displays needed supernav elements
    function check_if_loggedin(){
        $this->load->library('session');
        # user has loggedin Val = 1 and valid session_id
        $loggedInSetSuccess = 1;
        $sess = $this->session->userdata('session_id');
        $sessionsDbCompare = $this->db->get_where('Client',array('session_id'=>$sess,'loggedIn'=>$loggedInSetSuccess));
        // no session id for user in database... load login
        if($sessionsDbCompare->num_rows() == 1 ){
                $this->load->view('supernavigationloggedin.php');
                $this->load->view('primarynavigation.php');        
        }
        // otherwise problem with session count for the user is greater than 1.
        // Regenerate values
        elseif($sessionsDbCompare->num_rows() > 1){
            #remove current errorneous [session_id] data
                $this->session->unset_userdata();
            #reset [session_id] data
                $this->session->set_userdata();
            # load logged in views, given single session id exists.
                $this->load->view('supernavigationnotloggedin.php');
                $this->load->view('primarynavigation.php');               
        }

        // otherwise problem with session or loggedIn ... show login form.
        else{
            #remove current errorneous [session_id] data; load not logged in views.
            $this->session->unset_userdata();
            $this->load->view('supernavigationnotloggedin.php');
            $this->load->view('primarynavigation.php');     
        }

    }

}
?>

The problem is when I visit this page @ localhost/mysite it loads the following view : homepage.php and this model (above) called homepagemodel.php loads too, but a session is being created as soon as I load the page, how do I get it to be only if{} block is executed ? If I put it inside the if{} block, then a session will not be created in time using $this->load->library('session'); .

Anyone? I’ve been trying various fixes for this, but it keeps making duplicate rows with duplicate session values

  • 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-14T05:58:47+00:00Added an answer on June 14, 2026 at 5:58 am

    Well, I am not sure if this is what you need, but here we go…

    function check_if_loggedin()
    {        
        $is_logged = $this->session->userdata('loggedIn');
        $sess = $this->session->userdata('session_id');
        $sessionsDbCompare = $this->db->get_where('Client',array('session_id'=>$sess));
    
        if ($is_logged == 1 && $sessionsDbCompare->num_rows() == 1)
        {
            $this->session->set_userdata('loggedIn', 1);
            $this->load->view('supernavigationloggedin.php');
            $this->load->view('primarynavigation.php');
        }
        else
        {
            $this->session->unset_userdata();
            $this->load->view('supernavigationnotloggedin.php');
            $this->load->view('primarynavigation.php');  
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have codeigniter model like this <?php class Model_Login extends CI_Model{ function __construct(){ parent::__construct();
I have a function in my Comic Model as such: <?php class Comic extends
I have a model with two functions, like this: <?php class FotoModel extends CI_Model
I have this model at app/models/product.php : class Product extends AppModel { var $hasAndBelongsToMany
I have the following model : class Model extends BaseModel { public function save($conn
I have a Model.class.php and a Bag.class.php, the Bag class extends the Model class.
I have a Model called blog_model. The code for its constructor is below: class
I have written two functions like below in my model class. public function fetchByUsername($username)
I have model BaseUser.class.php User.class.php UserTable.class.php In user Class I have been override the
Quick background: I'm programming in PHP, I have a domain model with a separate

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.