Welcome Guest, Not a member yet? Register   Sign In
Help session grab user_id from database
#35

[eluser]Samus[/eluser]
[quote author="Ed Robindon" date="1338002967"]Here's a login page that I wrote to test with. Session and database are autoloaded in autoload.php. It has no validation just DB access:

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

class Login extends CI_Controller {
  
  public function index()
{
  $this->load->view('login');
}
  
  public function checkuser()
  {
    $uid = $this->input->post('userid');
    $pwd = $this->input->post('password');
    $q = $this->db->query("select * from users where user = '$uid'");    
    $row = $q->row();
    $data = array('row'=>$row);
    $this->session->set_userdata($data);
    echo '<pre>';
    print_r($this->session->userdata);
    echo 'User record id: '.$this->session->userdata['row']->id;
  }
}

/* End of file login.php */
/* Location: ./application/controllers/login.php */

View:

Code:
<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Login/Session Testing&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form method="post" action="/ciproject/index.php/login/checkuser"&gt;
<label>User Id:</label>
&lt;input type="text" id="userid" name="userid"/&gt;&lt;br/>
<label>Password:</label>
&lt;input type="text" id="password" name="password"/&gt;&lt;br/>
&lt;input type="submit" value="Submit"/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

I open a copy of FF and run it and it shows me one id based on the user I use.

I open another copy of FF and run it as a different user and I get a different session id as well as the proper user.

Thus, I must conclude that the CI sessions handler is working properly...

Don't know what else to tell you. Sad[/quote]
Prone to SQL injection mate. Wink


Messages In This Thread
Help session grab user_id from database - by El Forum - 05-23-2012, 08:16 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 08:36 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 08:40 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 08:43 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 08:45 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 08:52 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 08:56 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 08:58 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 09:01 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 09:06 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 09:07 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 09:13 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 09:15 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 09:20 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 09:21 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 10:19 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 10:22 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 10:25 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 10:29 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 10:30 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 10:37 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 10:42 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 11:07 AM
Help session grab user_id from database - by El Forum - 05-23-2012, 12:42 PM
Help session grab user_id from database - by El Forum - 05-24-2012, 08:50 AM
Help session grab user_id from database - by El Forum - 05-24-2012, 09:06 AM
Help session grab user_id from database - by El Forum - 05-24-2012, 09:16 AM
Help session grab user_id from database - by El Forum - 05-24-2012, 09:35 AM
Help session grab user_id from database - by El Forum - 05-24-2012, 09:37 AM
Help session grab user_id from database - by El Forum - 05-24-2012, 10:30 AM
Help session grab user_id from database - by El Forum - 05-24-2012, 10:41 AM
Help session grab user_id from database - by El Forum - 05-25-2012, 08:57 AM
Help session grab user_id from database - by El Forum - 05-25-2012, 08:12 PM
Help session grab user_id from database - by El Forum - 05-25-2012, 08:29 PM
Help session grab user_id from database - by El Forum - 05-26-2012, 12:35 AM
Help session grab user_id from database - by El Forum - 05-26-2012, 03:01 AM
Help session grab user_id from database - by El Forum - 05-26-2012, 03:37 AM
Help session grab user_id from database - by El Forum - 05-26-2012, 09:03 AM
Help session grab user_id from database - by El Forum - 05-26-2012, 11:35 AM
Help session grab user_id from database - by El Forum - 05-28-2012, 01:35 AM
Help session grab user_id from database - by El Forum - 05-28-2012, 03:13 AM
Help session grab user_id from database - by El Forum - 05-29-2012, 04:40 AM
Help session grab user_id from database - by El Forum - 05-29-2012, 07:56 AM
Help session grab user_id from database - by El Forum - 05-29-2012, 09:52 AM
Help session grab user_id from database - by El Forum - 05-29-2012, 09:54 AM
Help session grab user_id from database - by El Forum - 05-29-2012, 11:37 AM
Help session grab user_id from database - by El Forum - 05-29-2012, 12:57 PM
Help session grab user_id from database - by El Forum - 06-09-2012, 09:07 PM
Help session grab user_id from database - by El Forum - 06-11-2012, 12:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB