Cant fill session inside class

Discussion in 'PHP' started by AmidalaX, Apr 13, 2010.

  1. #1
    Hi there, I have little problem. I have class named listing - for product listing and I have few sections. I want to reset filter when Im in another section. I made it this way, but its not working.. I cant fill $_SESSION['sekc'] with actual value... Can anybody tell me why? Thanks...

    
    class listing
    {	
    	function __construct($section)
    	{
    		$this->section = clean_text($section);	
    		
    		echo 'old - ' . $_SESSION['sekc'] . '<br />'; //Print old sekc - never changes
    		echo 'new - ' . $this->section . '<br />';	//Print new section
    		
    		if ($_SESSION['sekc'] != $this->section)
    		{
                           //some unsets....
    		}
    		unset($_SESSION['sekc']);
    		echo $this->section; //Print correct value, the new section
    		$_SESSION['sekc'] = $this->section;
    		echo $_SESSION['sekc']; //Print correct value, the new section, but on another page reload I see the old value at top of the script. (ie: If i came from index, on top I see index and here I see the new value.)
    	}
    }
    PHP:
    Class calling:
    
    $listing = new listing('index');
    
    PHP:
    and in another scripts Im changing the value (index).
     
    AmidalaX, Apr 13, 2010 IP
  2. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #2
    add session_start()
     
    guardian999, Apr 13, 2010 IP
  3. AmidalaX

    AmidalaX Greenhorn

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Its there and server is using session.autostart.

    EDIT: Hmm, bug is somewhere in the script, but not in these few lines... If I use them alone, all is ok, but in website nope...
     
    Last edited: Apr 13, 2010
    AmidalaX, Apr 13, 2010 IP
  4. AmidalaX

    AmidalaX Greenhorn

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    Ouch, FAIL... I was calling this class in index.php and I had "ErrorDocument 404 /" in my htaccess. So when the error 404 was called, it calls index and it overwrites session....
     
    AmidalaX, Apr 14, 2010 IP