Welcome Guest, Not a member yet? Register   Sign In
Session problem
#1

[eluser]rbncha[/eluser]
How to flush session data when a new browser session is closed, so that I won't get the session data next time I open up the browser. I am creating a shopping cart with CodeIgniter. After adding some products in cart, I closed the browser (all borwser instances). And when I open the browser and what I see is the same cart data are there in my cart. That means, CodeIgniter doesn't kill the previous browser session. This seem a big problem to me.

Any one can help me ? Did I miss something or I don't know to use the session. Note that products are stored in session using CodeIgniter session id
Code:
$this->session->userdata('session_id')
#2

[eluser]rbncha[/eluser]
Hello,
Isn't there anyone to reply me ?
#3

[eluser]Mackstar[/eluser]
I wonder if deleting the

$config['sess_expiration'] = 7200;

would set mean that the session cookie would default to the length of the brower session. Just like in PHP's set-cookie. In which case this would delete your flash data. But it would also mean that as long as the brower is not closed the session stays alive.

Cheers

Richard
#4

[eluser]Mackstar[/eluser]
Actually you need to go into libraries/Session.php and change
Code:
// Set the cookie
setcookie(
    $this->sess_cookie_name,
    $cookie_data,
    $this->sess_expiration + time(),
    $this->cookie_path,
    $this->cookie_domain,
    0
);
to
Code:
// Set the cookie
setcookie(
    $this->sess_cookie_name,
    $cookie_data,
    0,
    $this->cookie_path,
    $this->cookie_domain,
    0
);
#5

[eluser]drewbee[/eluser]
Right. This is the way the stock CI Session class works. I wrote up a quick fix with a new configuration option over here...

http://ellislab.com/forums/viewthread/109645/#553043
#6

[eluser]Mackstar[/eluser]
Hi, there is a bit of a hacky way to do this with out altering system files. (Which I would do if it was only the flash notices you were worried about)

when you set the flash notice you can use setcookie("notice_present", true); - this expires when the browser session expires.

Then on the message you can put

Code:
if($this->session->flashdata('notice')&&$_COOKIE["notice_present"])
        echo '<div id="notice">'.$this->session->flashdata('notice').'</div>';
#7

[eluser]Mackstar[/eluser]
But you would also have to add a way of clearing the old flash notice session data....

You can do that instead...?
#8

[eluser]drewbee[/eluser]
My method isn't altering system files... it's extending them Smile I still have the original CI session class... but I've extended and changed so much that the base class really doesn't get much use lol.

Still haven't had any problems upgrading... and IMO have made the session class 100 times better. It maintains backwards compatibility with CI, and gives me what I need in terms of better performance and more custom data imported with 1 query.
#9

[eluser]Mackstar[/eluser]
Thanks for that, to be honest I didn't have a good read of your post, but your extension of the CI session sounds good. I will look into it more sometime

Cheers

Richard
#10

[eluser]drewbee[/eluser]
As always. Just remember, in terms of CI, if you are changing a core file you are 99.9% of the time, doing it wrong. Smile I have only run across a select handful of cases where I truly needed to modify the core. 1. being the database stuff (can't extend), and the other is the absolute true core ci files. Anything within libraries, helpers, and that other stuff can be extended.




Theme © iAndrew 2016 - Forum software by © MyBB