Welcome Guest, Not a member yet? Register   Sign In
Tank_Auth error message when session expires
#1

[eluser]jeanv[/eluser]
Hi !

i'm using Tank_Auth library, and it works very well excepted for one thing: when session (stored in database) expires there's this error message:

Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at E:\program_files\wamp\www\codeigniter\app_ci\controllers\contact.php:1)

Filename: libraries/Session.php

Line Number: 408

and the same message for line 662,

and this message:

Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at E:\program_files\wamp\www\codeigniter\app_ci\controllers\contact.php:1)

Filename: helpers/url_helper.php

Line Number: 541

here is my code in contact controller:

Code:
function __construct()
    {
        parent::Controller();
        
        $this->load->library('tank_auth');
                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();
            $data['online_users']    = $this->tank_auth->count_online_users(); // new function

            $this->load->vars($data);
        
            // load model
            $this->load->model('mdl_contact','',TRUE);
        }
    }

Anyone can help please ?

the only solution i found is to put value 0 to $config['sess_expiration'] but it's not a real solution.
#2

[eluser]dinhtrung[/eluser]
Seems like the error appears because of setcookie() function in Sessions library, not by Tank_Auth. Because redirect() use header to redirect the page, too, and setcookie() also a header function, so this collision appears. As a replacement, you could render an auto-update page and redirect later. I usually did this:
Code:
function __construct()
{
    parent::__construct();
    if ($this->tank_auth->is_logged_in == FALSE){
        $info['message'] = "You are not logged in. Please login to continue.";  # Message to display to the user.
        $info["url"] = site_url('auth/login');  # The url we gonna redirect to
        # $info['time'] = 2; # Number of seconds the info page should be display before redirect.
        echo $this->load->view('info', $info, TRUE);
        exit;
    } else ....
For the info view in the last echo statement:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="refresh" content="&lt;?= (isset($time))?$time:'1000' ?&gt;; URL=&lt;?= $url; ?&gt;"&gt;
&lt;title&gt;Information&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h3>Information</h3>
<p class='notice'>&lt;?= $message; ?&gt;</p>
&lt;/body&gt;
Please feed back if this method works. Wink
#3

[eluser]jeanv[/eluser]
hi, thanks !

it's a good idea to do that, but i still have my error message... (cannot modify header...).

i really don't know where it comes from.
#4

[eluser]jeanv[/eluser]
actually it seems that the problem comes before controller login... is that possible ? I'm getting nuts with that ! Please help ! ;-)




Theme © iAndrew 2016 - Forum software by © MyBB