Welcome Guest, Not a member yet? Register   Sign In
[solved] redirect() destroys session
#1

[eluser]Unknown[/eluser]
Hi!

I'm quite new to the Code Igniter framework and have recently begun working on a medium scale social application that uses CI.

I have a problem with redirects and session. On every controller that needs the user to be authenticated I use this code:

Code:
$authenticated = $this->session->userdata("loggedIn");
if($authenticated){
    //DO SOME EXITING STUFF
}

All works well and I can browse the site and see only data that is related to my account. But problems arise when I have to a redirect. I have a page that lets the user to create new groups. In the controller, after the input has been validated I push the new row to database and then redirect to the same page, like this:

Code:
redirect("groups/index", "refresh");

And in the index-function in the groups-controller I have this:

Code:
$authenticated = $this->session->userdata("loggedIn");
if($authenticated){
    //SHOW THE GROUPS THE USER BELONGS AND/OR IS OWNER OF
}else{
    redirect("aarre/index", "refresh");//The front page
}

This throws me back to the front page and seems to destroy the session since I have to log back in.

We use database for storing the sessions.

Any help is greatly appreciated...
#2

[eluser]Unknown[/eluser]
After examining the cookies sent from our server I think I have found the answer.

There were identically named cookies from two domains: domain.com and www.domain.com. config.php had domain.com configured. And in our view-templates we had mixed www.domain. and domain.com. So yeah, it's no surprise that CI couldn't find authenticated user from the session.

Anyway, thanks for a useful framework. There's still lot for me to learn(one error at a time).
#3

[eluser]phantom-a[/eluser]
[quote author="hukka" date="1221433732"]After examining the cookies sent from our server I think I have found the answer.

There were identically named cookies from two domains: example.com and www.example.com. config.php had example.com configured. And in our view-templates we had mixed www.example. and example.com. So yeah, it's no surprise that CI couldn't find authenticated user from the session.

Anyway, thanks for a useful framework. There's still lot for me to learn(one error at a time).[/quote]

Hey just a little info on something a petpev of mine..
Make sure to use example.com in examples or in documentation. Domain.com is a real website.
Example.com is not and reserved for documentation. Smile

Otherwise sites like "somesite.com" "domain.com" etc. get free backlinks and traffic.
As you can imagine it would be quite profitable if you downed "domain.com" with all those free links. Specially if your Parked it, like this site
http://www.mywebsite.com/ which has 20K backlinks now.




Theme © iAndrew 2016 - Forum software by © MyBB