• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session Variable Lost

#1
[eluser]baudday[/eluser]
I have a session variable called $sizes that is a two dimensional array. I set this variable in a function called "quantities." After I do this and some other things, I load a view. A form is submitted from that view and that form gets processed by a function called "ink." For some reason I am losing the session variable going from the view to the "ink" function. I did a print_r in "quantities" and in the view and the variable was still set, but once the program goes to the "ink" function, the session variable is cleared. Does anyone know why this could possibly be happening? If you need to see my code I can post it. Thanks.

#2
[eluser]baudday[/eluser]
Almost forgot, I set about 2 other session variables at the same time I set $sizes, and they don't get lost. I'm really stumped on this one.

#3
[eluser]frist44[/eluser]
post code from both functions.

#4
[eluser]baudday[/eluser]
Code:
function quantities()
    {
        $total = 0;

        if($this->form_validation->run('qty') == FALSE){}
        
        else
        {
        
            foreach($_POST['sizes'] as $color=>$swatch)
            {
            
                $total = $total + array_sum($swatch);
                foreach($swatch as $size=>$qty)
                {
                
                    $sizes[$color][$size] = $qty;
                
                }
            
            }
            
            unset($qty);
            
            $this->load->model('shirts');
            if($total >= 24 && $total <= 47)
            {
                $mult = $this->shirts->getPricePoints(24);
                $qty = 24;
            }
            else if($total >= 48 && $total <= 71)
            {
                $mult = $this->shirts->getPricePoints(48);
                $qty = 48;
            }
            else if($total >= 72 && $total <= 2499)
            {
                $mult = $this->shirts->getPricePoints(72);
                $qty = 72;
            }
            else if($total >= 2500 && $total <= 4999)
            {
                $mult = $this->shirts->getPricePoints(2500);
                $qty = 2500;
            }
            else if($total >= 5000 && $total <= 9999)
            {
                $mult = $this->shirts->getPricePoints(5000);
                $qty = 5000;
            }
            else if($total >= 10000)
            {
                $mult = $this->shirts->getPricePoints(5000);
                $qty = 10000;
            }
            
            $info = array('total' => $total,
                                        'mult' => $mult,
                                        'sizes' => $sizes,
                                        'qty' => $qty
                                        );
            $this->session->set_userdata($info);
            $this->load->view('ink');
        
        }
    
    }
    
    function ink()
    {
    
        if($_POST['ink'] == 0)
        {
        
            $data['error'] = 'You must print at least one color.';
            $this->load->view('ink', $data);
        
        }
        
        else
        {
        
            $info['pname'] = $_POST['name'];
            $info['pnum'] = $_POST['num'];
            $inks = $_POST['ink'];
            $this->load->model('shirts');
            foreach($inks as $key=>$num)
            {
            
                if($num != 0)
                {
                    
                    $info['qty'][$key] = $num;
                    $info['price'][$key] = $this->shirts->getInkPrice($this->session->userdata('qty'), $num);
                
                }
            
            }
            
            $data['inks'] = $info;
            
            $this->session->set_userdata($data);
            unset($data);
            $this->calculate();
            
        }
        
    }

#5
[eluser]danmontgomery[/eluser]
Cookies have a 4kb size limit, you are probably hitting that... Try enabling database sessions.

#6
[eluser]baudday[/eluser]
I'm just confused by this because, as I mentioned, it has no problem passing to the view, but once I go back to "ink" from the view it gets cleared at some point for some reason.

#7
[eluser]baudday[/eluser]
Do you think you could point me to a good link where I can learn what database sessions are and how to use them? I think that would be the best option because this array could actually end up being quite large.

#8
[eluser]baudday[/eluser]
Okay found it. For future reference, they describe how to enable it in the Session Class section of the User guide. http://ellislab.com/codeigniter/user-gui...sions.html


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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