[eluser]SitesByJoe[/eluser]
Okay, I'm scratching my head over this one so maybe some of you guys have some advice.
I built a site
http://www.collegescholarships.com and I use Sessions and Erkanaauth.
When a user logs in 2 things should happen:
1. The top of the pages give a "Hi There {username)" messages and,
2. The link in the navigation that says "Find Scholarships" changes to "My Scholarships".
I thought everything was working fine, but the weirdest thing happens:
On a couple pages on the site, my session disappears. If I go to a different page it comes back!
So digging in a little further, here's the view that shows the account message:
Code:
<?php if ($this->erkanaauth->try_profile_session_login()) : ?>
<em>Hi there, <?php echo $this->session->userdata('first_name'); ?>!</em>
<?php echo anchor('profiles/logout', 'Logout', array('class' => 'log_in_out')); ?>
<?php else : ?>
<em>Already have an account?</em>
<?php echo anchor('profiles/login', 'Login', array('class' => 'log_in_out')); ?>
<?php endif; ?>
And the navigation does the same:
Code:
<?php if ( ! $this->erkanaauth->try_profile_session_login()) : // not logged in ?>
<li id="scholarships_link"><?php echo anchor('scholarships/search', 'Find a Scholarship' . is_active_link($active_link, 'scholarships_link')); ?></li>
<?php else : ?>
<li id="dashboard_link"><?php echo anchor('profiles', 'My Scholarships' . is_active_link($active_link, 'dashboard_link')); ?></li>
<?php endif; ?>
We trace that back to the Erkanaauth library, where I have this function:
Code:
function try_profile_session_login()
{
if ($this->CI->session->userdata('profile_id'))
{
$query = $this->CI->db->query('SELECT COUNT(*) AS total FROM profiles WHERE id = ' . $this->CI->session->userdata('profile_id'));
$row = $query->row();
if ($row->total != 1)
{
// Bad session - kill it
$this->profile_logout();
return FALSE;
}
else
{
return TRUE;
}
}
else
{
return FALSE;
}
}
The logout function does this:
Code:
function profile_logout()
{
$this->CI->session->set_userdata(array('profile_id' => FALSE));
}
I don't think the user is logged out since going to a new page brings the session back.
What do you think is going wrong?
It's only the homepage and maybe 3 other pages that do this. Too weird!
Here's my home/index function (one of the bad pages). You can see I'm not touching the session.
Code:
function index()
{
// load the homepage
$this->load->model('Pages_model');
$data['pages'] = $this->Pages_model->get_page_by_slug('homepage');
// use our page data to populate the meta tags
$page = $data['pages']->row();
$data['title'] = $page->title;
$data['description'] = $page->description;
$data['keywords'] = $page->keywords;
// if we're using an auto page navigation
$data['nav_links'] = $this->Pages_model->get_pages_for_nav();
// add in extra stuff for more keywords etc
$this->load->model('News_model');
$data['widget_award_of_the_month'] = $this->News_model->get_all_news(FALSE, 'award of the month');
$data['widget_news'] = $this->News_model->get_all_news(FALSE, 'news');
// asides
$data['asides'] = $this->Pages_model->get_all_asides();
$data['categories'] = $this->Pages_model->get_all_categories();
$data['category_pages'] = $this->Pages_model->get_category_pages();
$data['sidebar_pages'] = $this->Pages_model->get_sidebar_pages();
// set our content type
$data['content_type'] = 'dynamic';
// build and send
$this->load->view('templates/homepage', $data);
// cache our homepage for faster delivery
$this->output->cache(60);
}