Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter - check if user is logged and exists (it's a real user)

I'm trying to set session data for users when they log in to my website.

So if the user exists in db, I set a session data like : $this->session->set_userdata('user_exists','1');

Now every time i want to check if user exists and is logged i do:

if($this->session->userdata('user_exists')){
 //do somenthing for logged user
}

Now I'm wondering if this means that user is logged and exists in the database since he logged and I set him a session param, is this true? Or I'll get security problems?

NB: I'm using session database

like image 619
itsme Avatar asked Jul 09 '13 08:07

itsme


People also ask

What is Register_email_exists () in CodeIgniter?

Using Codeigniter, this URL is a new function in the controller used for registration. In this example, the register_email_exists () function returns true or false, after checking the entered form value against the database.

How does a username check work?

When the cursor leaves the username field (an event referred to in JavaScript as onblur, a username check is done in the background through an ajax call to the server without the user even clicking the submit button.

How to validate if a user already exists in the database?

If a user with the provided username already exists in the database, a validation message with appropriate styling is displayed right away. Create a file named register.php and paste this code in it:

Where can I find the user agent name definitions?

The user agent name definitions are located in a config file located at: app/Config/UserAgents.php. You may add items to the various user agent arrays if needed. When the User Agent class is initialized it will attempt to determine whether the user agent browsing your site is a web browser, a mobile device, or a robot.


1 Answers

//session encryption is mandatory

  $sess_id = $this->session->userdata('user_id');

   if(!empty($sess_id))
   {
        redirect(site_url().'/reports');

   }else{

        $this->session->set_userdata(array('msg'=>'')); 
        //load the login page
        $this->load->view('login/index');        
   }    
like image 50
Sundar Avatar answered Nov 14 '22 22:11

Sundar