Welcome Guest, Not a member yet? Register   Sign In
logged_in state different when writing url or clicking
#1

[eluser]webnology[/eluser]
Hi all,

I'm using dx_auth. When I'm logged in, I lose my logged_in state if I click on my webpage to launch an event in the controller, for example /form/addCustomer. If I type the url, starting on the same page, then I keep my logged_in state.

Any idea why this happens?

All help really appreciated,
Michel
#2

[eluser]Aziz Chouhan[/eluser]
hi michel
i think you are doing mistake in making logged_in state.for this do like this.
first do this in your login controller.
Quote: $username=$this->input->post('username');
$userpass=$this->input->post('userpass');

$this->load->model('Users_model');
$query = $this->Users_model->get_user_detail($username,$userpass);

if($query->num_rows()>0)
{
$row=$query->row();

if( ($row->user_type=='admin') )
{

$newdata = array(
'user_id' => $row->user_id,
'user_name' => $row->user_name,
'user_email' => $row->user_email,
'user_type' => $row->user_type,
'logged_in' => TRUE );
$this->session->set_userdata($newdata);

//$username = $this->session->userdata('user_name');

redirect('/main/','location');
}
else
{ redirect('/loginform/','location'); }
}
else
{
redirect('/loginform/','location');
}

then check this on your each controller

Quote:if( $this->session->userdata('user_name')=='')
{
redirect('/loginform/','location');
}
else
{
// do any task related to your controller
}

end.
this will work perfectly as i am using this very efficiently.
if u need full resource code then tell me further.
ok thanks
#3

[eluser]webnology[/eluser]
Hi Aziz, thanks for helping. The thing is, I use the exact same code on another project, and that works fine. The only difference is the server where the website runs. I prefer not to touch the login code from dx_auth, so I don't cretae extra unknown problems later. There must be sth wrong with the config or the server settings?
#4

[eluser]webnology[/eluser]
Hi all,

I've upgraded everything, now running CI2 and Tank_Auth instead of dx_aut. I have exactly the same issue. I can login, but when I go to one of my own controllers, I get logged out. If I use the welcome message, which is delivered with Tank_auth, it works fine.

This is the Tank_auth code, which works:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller
{
    function __construct()
    {
        parent::__construct();

        $this->load->helper('url');
        $this->load->library('tank_auth');
    }

    function index()
    {
        if (!$this->tank_auth->is_logged_in()) {
            redirect('/auth/login/');
        } else {
            $data['user_id']    = $this->tank_auth->get_user_id();
            $data['username']    = $this->tank_auth->get_username();
            $this->load->view('welcome', $data);
        }
    }
}


This is the my code, which doesn't work:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Form extends CI_Controller
{
    function __construct()
    {
        parent::__construct();

        $this->load->helper('url');
        $this->load->library('tank_auth');
    }

    function addCustomer()
    {
        if (!$this->tank_auth->is_logged_in()) {
            redirect('http://www.amazon.com/');
        } else {
            redirect('http://www.google.be/');
        }
    }
}

If I go directly to the url (typing it, instead of clicking), I stay logged in.

As far as I can see, there is no difference in the code. Any ideas someone?

Many thanks,
Michel
#5

[eluser]webnology[/eluser]
ok, it's getting better. Works on IE, not on FF. More to come.




Theme © iAndrew 2016 - Forum software by © MyBB