Basket not retaining array session.

Discussion in 'PHP' started by robg, Jul 14, 2007.

  1. #1
    Hi all, hope someone can help with this. It's driving me bonkers :D

    I wondered if some body knows how to retain the session ($_SESSION['addon']) for my shopping basket, i lose it when i navigate to another page or refresh the page. The $_SESSION['cart'] is fine. Thanks in advance for your time and help!

    This works on my local version just not on the remote ???

    here is the header code:

    <?php
    session_start();
    if (!isset($_SESSION['cart']))
    {
    	$_SESSION['cart'] = array();
    }
    if (!isset($_SESSION['addon']) || !is_array($_SESSION['addon']))
    {
    	$_SESSION['addon'] = array();
    }
    
    if (isset($_POST['bid']))
    {
    	$_SESSION['cart'][] = $_POST['bid'];
    	
    	$addonarrays = array();
    	
    	if (isset($_POST['addon']) && is_array($_POST['addon'])) 
    	{
          $addonarrays = $_POST['addon'];
    	}  
    	
    	foreach($addonarrays as $addonarray)
    	{
    	$_SESSION['addon'][] = $addonarray;
    	}
    	
    header('location: ' . $_SERVER['PHP_SELF'] . '?' . SID);
    exit();
    }
    if (isset($_GET['empty']))
    {
    	unset($_SESSION['cart']);
    	unset($_SESSION['addon']);
    header('location: ' . $_SERVER['PHP_SELF'] . '?' . SID);
    exit();
    }
    Code (markup):
    and here is the form that submits it

    <form action="basket.php" method="post">
    						
    	
    				 <?php 
    					$addon = @mysql_query("SELECT DISTINCT id, refnum, name FROM addon, addonsubmenucat WHERE id=addonid AND catid=2 LIMIT 0, 4");
    					while ($addons = mysql_fetch_array($addon))
    					{
    						$addonid = $addons['id'];
    						$addonname = $addons['name'];
    						$addonrefnum = $addons['refnum'];
    						
    						echo "<label>$addonname</label><input type='checkbox' name='addon[]' value='$addonid'>\n";
    						
    					}
    				 ?> 
    			
    				 <?php 
    					$addon = @mysql_query("SELECT DISTINCT id, refnum FROM addon, addonsubmenucat WHERE id=addonid AND catid=2 LIMIT 0, 4");
    					while ($addons = mysql_fetch_array($addon))
    					{
    						$addonrefnum = $addons['refnum'];
    						
    						echo "<td align='center'><img src='thumbnailpictures/$addonrefnum.gif'>\n";
    					}
    				 ?> 
    				
    				<input type="hidden" name="bid" value="<?php echo "$id" ;?>" />
    				<input type="submit" id="buybutton" value="Add to basket" />
    Code (markup):
    thanks
     
    robg, Jul 14, 2007 IP
  2. robg

    robg Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm using PHP Version 5.2.2 on Windows/apache on my local computer and my remote host is using PHP Version 4.4.1 on linux/apache.

    here is session output for sessions on remote:

    Session Support 	enabled
    Registered save handlers 	files user
    
    Directive	                     Local Value	Master Value
    session.auto_start	               Off	              Off
    session.bug_compat_42	           On	                 On
    session.bug_compat_warn	          On	                On
    session.cache_expire	             180	           180
    session.cache_limiter	           nocache	      nocache
    session.cookie_domain	        no value	     no value
    session.cookie_lifetime	               0	              0
    session.cookie_path	              /	                      /
    session.cookie_secure	           Off	                  Off
    session.entropy_file	           no value	       no value
    session.entropy_length	            0	                    0
    session.gc_divisor	              100	            100
    session.gc_maxlifetime	           1440	                1440
    session.gc_probability	              1	                      1
    session.name	                 PHPSESSID	    PHPSESSID
    session.referer_check	         no value	     no value
    session.save_handler	           files	           files
    session.save_path	/home/phpsessions  /home/phpsessions
    session.serialize_handler	  php	                   php
    session.use_cookies	          On	                   On
    session.use_only_cookies	Off	                  Off
    session.use_trans_sid	          Off	                    Off
    
    Code (markup):
     
    robg, Jul 15, 2007 IP