[eluser]tahakirmani[/eluser]
Hi
I am trying to create session in my login form. When a user opens my website Login Page appers, after login user can access to the dashboard. I want the user to land on Dashboard page if he is already login. Right now its not storing session information. I have autoload session and have written the following code. Kindly check it and guide me how to resolve this problem.
//Controller
Code: public function index()
{
$data['products_data']= $this->products_model->all_products();
if (!$this->session->userdata('username'))
{
$this->load->view('login');
}
else
{
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('password','Password','required');
if ($this->form_validation->run()== false)
{
$this->load->view('login');
}
else{
$username= $this->input->post('username');
$password= $this->input->post('password');
if(!$this->products_model->login_model($username,$password))
{
$this->load->view('login');
echo "Invalid Username or Password";
}
else
{
$sess_data= array(
'username'=> $username,
'login_status'=>'1'
);
$session_data = $this->session->set_userdata($sess_data);
$this->load->view('header');
$this->load->view('dashboard');
$this->load->view('footer');
}
}
}
}
[eluser]tahakirmani[/eluser]
Anyone for the help?
[eluser]Kenan[/eluser]
try to add this code after set_userdata($sess_data):
Code: $this->session->all_userdata()
[eluser]tahakirmani[/eluser]
[quote author="Kenan" date="1390375805"]try to add this code after set_userdata($sess_data):
Code: $this->session->all_userdata()
[/quote]
Thanks for the reply.
I have added these lines in my code, but still there is no change in the output.
[eluser]Kenan[/eluser]
never mind, then u have to wait for the others' help, i am new in ci, i can give u workfull code in classic php (i think u also know it) but in ci my knowledge is not enough
[eluser]tahakirmani[/eluser]
[quote author="Kenan" date="1390384993"]never mind, then u have to wait for the others' help, i am new in ci, i can give u workfull code in classic php (i think u also know it) but in ci my knowledge is not enough[/quote]
Yes i know how to set and test session in classic php, but in codeigniter i am unable to understand that how to test if session is already set or not.
[eluser]Kenan[/eluser]
[quote author="tahakirmani" date="1390385580"][quote author="Kenan" date="1390384993"]never mind, then u have to wait for the others' help, i am new in ci, i can give u workfull code in classic php (i think u also know it) but in ci my knowledge is not enough[/quote]
Yes i know how to set and test session in classic php, but in codeigniter i am unable to understand that how to test if session is already set or not. [/quote]
well, so, i am rewriting my apps from the classic php into the ci, when i'll reach sessions (i seem it'll be today or tomorrow) and it'll work, i'll give my example
[eluser]tahakirmani[/eluser]
[quote author="Kenan" date="1390386808"][quote author="tahakirmani" date="1390385580"][quote author="Kenan" date="1390384993"]never mind, then u have to wait for the others' help, i am new in ci, i can give u workfull code in classic php (i think u also know it) but in ci my knowledge is not enough[/quote]
Yes i know how to set and test session in classic php, but in codeigniter i am unable to understand that how to test if session is already set or not. [/quote]
well, so, i am rewriting my apps from the classic php into the ci, when i'll reach sessions (i seem it'll be today or tomorrow) and it'll work, i'll give my example[/quote]
Ok, Thanks
[eluser]Kenan[/eluser]
[quote author="tahakirmani" date="1390387106"][quote author="Kenan" date="1390386808"][quote author="tahakirmani" date="1390385580"][quote author="Kenan" date="1390384993"]never mind, then u have to wait for the others' help, i am new in ci, i can give u workfull code in classic php (i think u also know it) but in ci my knowledge is not enough[/quote]
Yes i know how to set and test session in classic php, but in codeigniter i am unable to understand that how to test if session is already set or not. [/quote]
well, so, i am rewriting my apps from the classic php into the ci, when i'll reach sessions (i seem it'll be today or tomorrow) and it'll work, i'll give my example[/quote]
Ok, Thanks [/quote]
never mind
[eluser]Kenan[/eluser]
dear friend, i have realized session storing in ci, and it works
Code: $data = array(
'id' => $data['id'],
'email' => $data['email'],
'login' => $auth
);
$this->session->set_userdata($data);
i check it using it:
Code: $this->session->userdata('id');
$this->session->userdata('email');
$this->session->userdata('login');
|