Jump to content

Basket refresh


robgood

Recommended Posts

Hi, 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!

 

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();
}

Link to comment
Share on other sites

and here is the form that submits the data if it helps

 

<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" />

 

thanks

Link to comment
Share on other sites

Strange, as it works on my local machine.  The addons stay in the basket where as on remote version they disappear when the page is refreshed or you navigate away from basket page and then back to it.

 

Really racking my brains.  anymore ideas ???

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.