Welcome Guest, Not a member yet? Register   Sign In
Session data
#11

[eluser]triplewhat[/eluser]
I KNOW HOW TO RETREIVE IT. HOW DO YOU GET THE VALUE TO SET IT
#12

[eluser]Ajaxboy[/eluser]
I don't understand your question? how to get the value of what?
#13

[eluser]triplewhat[/eluser]
Code:
function validate()
{
  $this->db->select('username', 'password', 'title');
  $this->db->where('username', $this->input->post('username'));
  $this->db->where('password', $this->input->post('password'));
  $query = $this->db->get('users');
  
  if($query->num_rows == 1)
  {

   return $query;
  }
  
}

i select the data with this. How to I convert it to an array to put into session data?
#14

[eluser]Ajaxboy[/eluser]
This should work
Code:
function validate()
{
  $this->db->select('username', 'password', 'title');
  $this->db->where('username', $this->input->post('username'));
  $this->db->where('password', $this->input->post('password'));
  $query = $this->db->get('users')->row_array();
  
  if($query)
  {

   return $query;
  }
  
}

I'd revise that code tho it looks some what insecure.
#15

[eluser]triplewhat[/eluser]
It doesnt work
#16

[eluser]Ajaxboy[/eluser]
It should, but you also have to make changes to your controller.

Code:
public function validate_credentials(){  
  $this->load->model('membership_model');
  $login_data = $this->membership_model->validate();
  
   if($login_data) // if the user's credentials validated...
  
   {

    $data = array(
     'username' => $login_data['username'],
     'logged_in' => true
    );

    $this->session->set_userdata($data);
    $data['main_content'] = 'home';
    $data['page_title'] = '<title>';
    $this->load->view('includes/template', $data);
   }else{  // incorrect username or password
    $this->index();
   }
  }

Also your login info has to actually match the db info
#17

[eluser]Ajaxboy[/eluser]
Code:
function validate()
{
  $this->db->select('username', 'password', 'title');
  $this->db->where('username', $this->input->post('username'));
  $this->db->where('password', $this->input->post('password'));
  $query = $this->db->get('users')->row_array();
  
  if($query)
  {

   return $query;
  }
  die("Your login info is not good");
}
you might want to try this...
#18

[eluser]triplewhat[/eluser]
Ok my login looks like this now. I am calling the session data in the header with

Code:
public function index() {
   $data['main_content'] = 'login_form';
   $data['page_title'] = 'Login';
   $this->load->view('includes/template', $data);
  }

  public function validate_credentials(){  
  $this->load->model('membership_model');
  $login_data = $this->membership_model->validate();
  
   if($login_data) // if the user's credentials validated...
  
   {

    $data = array(
     'username' => $login_data['username'],
     'title' => $login_data['title'],
     'logged_in' => true
    );

    $this->session->set_userdata($data);
    $data['main_content'] = 'home';
    $data['page_title'] = $title;
    $this->load->view('includes/template', $data);
I am calling the session data in the header with
Code:
$this->session->userdata('username')
$this->session->userdata('username')

It is finding the username, but still not the title
#19

[eluser]Ajaxboy[/eluser]
you have two times "$this->session->userdata('username')"
#20

[eluser]Ajaxboy[/eluser]
Like someone told me... I am not gonna do the thinking for you... lol..




Theme © iAndrew 2016 - Forum software by © MyBB