• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sessions and Template

#1
[eluser]rrasco[/eluser]
*Please see post #3 for updates: http://ellislab.com/forums/viewreply/575399/

I have an app that is having problems with session. I didn't build this app, I was just supposed to integrate it into the design. I utilized the template library to do this. However, I am having some issues with session data not being stored correctly.

I have a page that lists contests, and in doing so, it stores the contest_id as session data so it can be used on the next action. The action is enter($id), so an example URL would be: index.php/contests/enter/10.

If I echo $id, I get a result of 10. I use $id to assign the session data:

Code:
$this->session->set_userdata('contest_id', $id);

This should store 10 as session variable 'contest_id'. I can verify this by:

Code:
echo $this->session->userdata('contest_id'); // this returns a value of 10 as well

The problem is, when I attempt to use 'contest_id' it returns a value other than 10, it is actually assigning 'img' to the session item in the db. This happens with sessions db enabled/disabled. All other session data is being stored correctly.

Code:
a:7:{s:10:"contest_id";s:3:"img";s:3:"uid";s:1:"6";s:6:"logged";s:1:"y";s:9:"entry_fee";s:5:"25.00";s:3:"adu";s:6:"capear";}

This problem seems to arise after the Template library is used. Does anyone know if there are known issues with Template interfering with session data? Or any other reason this may happen?

TIA

#2
[eluser]rrasco[/eluser]
This is the template library I used:

http://williamsconcepts.com/ci/codeignit...rence.html

#3
[eluser]rrasco[/eluser]
I have narrowed the bug down a bit. I removed the templating system to eliminate that as a cause and isolated it down to a portion of code; code is notated. I am extremely new to CI and could use some guidance.

*NOTE: The forums were not liking the siteurl() parameters, so I omitted them.

Code:
function enter($id)
{
    if($this->session->userdata('logged') == 'y') {
        $data['login'] = '<img src="http://carpearticulum.com/arrow.gif">&nbsp;Logged in - <a href="'.site_url().'">Log out</a><br />';
    } else {
        $data['login'] = '<img src="http://carpearticulum.com/arrow.gif">&nbsp;<a href="'.site_url().'">Login</a> or <a href="'.site_url().'">Register</a><br />';
    }
    
    if($this->session->userdata('logged') == 'y') {
        $this->session->set_userdata('contest_id', $id);

        echo $this->session->userdata('contest_id'); // this returns the right value
        exit; // if I stop code here, the value is stored correctly, else it stores 'img'
        // Actually, I can exit the code anywhere before the end of the method and it works
        // but it stops the page from displaying, what happens after a view() call?

        $query = $this->db->select('*');
        $query = $this->db->where('id', $id);
        $query = $this->db->get('contests');
        if ($query->num_rows() > 0) {
                $row = $query->row();
                $data['contest_title'] = $row->title;
                $data['description'] = $row->description;
                $data['prize'] = $row->prize;
                $data['category'] = $row->category;
                $data['start'] = $row->start;
                $data['end'] = $row->end;
                $data['entry_fee'] = $row->entry_fee;
                $this->session->set_userdata('entry_fee', $row->entry_fee);    
        }
        $this->load->view('contests/enter_view', $data);

    } else {

        $this->session->set_userdata('contest_id', $id);
        $this->session->unset_userdata('member_page');
        
        $data['msg'] =  "If already registered please <a href='".site_url()."'>login</a> or please <a href='".site_url()."'>Register</a>";
        $this->load->view('home/login_or_register', $data);
    
    }
}

#4
[eluser]TheFuzzy0ne[/eluser]
I'm totally baffled. I wouldn't have thought the template library should have anything to do with sessions. Please let us know how you get on with tracing the problem.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.