Welcome Guest, Not a member yet? Register   Sign In
Geting Wrong Session Data using DB Session
#1

[eluser]Mizanur Islam Laskar[/eluser]
Hello,

I'm facing a trouble while using DB Session from the wiki http://codeigniter.com/wiki/DB_Session/. The thing is, my login page is on the home page and when I submit correct ID and Password, it authenticates and show me the correct username as my session value for the first time it redirects to the home page, but after that when I refresh myself that page or go to any other page, I get my session value as "assets"...well, regardless to say that my JS and CSS scripts are placed under mysite/assets/; but I think thats not the issue. Moreover, when I check in my phpMyAdmin, then it also shows that the value against the session variable is stored as "assets"...I think there is a simple fixing there in my code(given below)...so guys, need your expertisements here to help me:

My Partial CONTROLLER:
Code:
class Clients extends Controller
        {
        
          function Clients()
              {
             parent::Controller();
             $this->load->library(array('db_session'));
             }
            
          function index()
              {
            
              }            
         function welcome_client()
            {
             $this->db_session->set_userdata('client', $this->input->post('account_id'));
             $this->load->view('index',$data);
             }    
            
         }

My Partial VIEW:
Code:
<form action="welcome_client" method="post" id="login_form">
Client ID:<input id="account_id" name="account_id" type="text" size="10" /><br />
Password:<input id="account_password" name="account_password" type="password" size="10" /><br/>
              <div class="buttondiv" style="background-color:#D5D5D5; text-align:left;"><br/>
&lt;input name="Submit" type="submit" id="submit" class="submit_button" value="Login" style="height:23px;"  /&gt;
&lt;/form&gt;

My Partial config.php
Code:
$config['sess_cookie_name']     = 'http://localhost/project/mysite';
$config['sess_expiration']         = 7200;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']     = TRUE;
$config['sess_table_name']         = 'ci_sessions';
$config['sess_match_ip']         = TRUE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update']     = 300;

My Partial autoload.php
Code:
$autoload['libraries'] = array('database', 'db_session');

Plz note that I didn't show my model and its relevant controller's function to check my ID and Password against the database, since that part is working fine. So I simplified this post so that I want to store my session from whaever I typed as my ID on the view form.
#2

[eluser]thinkigniter[/eluser]
Hi Mizanur Islam Laskar

in your config.php file under config what values do...
Code:
$config['cookie_prefix']
$config['cookie_domain']
$config['cookie_path']
have ?
#3

[eluser]Mizanur Islam Laskar[/eluser]
Code:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path']    = "/";

Note that I want to test it in my local machine first..so need help on that both for local and in live...thanks in advance
#4

[eluser]thinkigniter[/eluser]
Sorry it's taken a while to get back to you.

Try changing your cookie path to...

Code:
$config['cookie_path']    = "/project/mysite/";
#5

[eluser]Mizanur Islam Laskar[/eluser]
Great to see you again. I have decided not to use db_session. Rather want to use CI's default session library. I've arranged to run it in my local machine. But when I try to run it on a domain server(pmsdap.mgncare.com), it shows successful message when it first redirect to a page, but when I get back to homepage, that session info is lost!!

Here is my partial of config.php:
Code:
$config['sess_cookie_name']     = 'pmsdap';
$config['sess_expiration']         = 7200;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']     = FALSE;
$config['sess_table_name']         = 'ci_sessions';
$config['sess_match_ip']         = TRUE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update']     = 300;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']        = "http://pmsdap.mgncare.com/";

Plz note that my server(pmsdap.mgncare.com) is running in PHP-5.0.4, where its 5.2.5 in my local machine

Again, thanks in advance.
#6

[eluser]thinkigniter[/eluser]
Got a question...
Shouldn't you be checking to see if the session data is set and then setting an d refreshing.

The way your code looks, to me, is that the next the page loads the session data is set again but with a NULL value.
E.G.
Code:
class Clients extends Controller
{
function Clients()
{
parent::Controller();
$this->load->library(array('db_session'));
}
            
function index()
{
$this->welcome_client();        
}
            
function welcome_client()
{
if( $this->session->userdata('client') == FALSE )
{
$this->db_session->set_userdata('client',$this->input->post('account_id'));

redirect('/Clients/welcome_client', 'refresh');

}else{
$this->load->view('index',$data);
}

}    

}

Or am I wrong?




Theme © iAndrew 2016 - Forum software by © MyBB