robgood Posted July 14, 2007 Share Posted July 14, 2007 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 https://forums.phpfreaks.com/topic/59943-basket-refresh/ Share on other sites More sharing options...
robgood Posted July 14, 2007 Author Share Posted July 14, 2007 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 https://forums.phpfreaks.com/topic/59943-basket-refresh/#findComment-298165 Share on other sites More sharing options...
robgood Posted July 14, 2007 Author Share Posted July 14, 2007 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 https://forums.phpfreaks.com/topic/59943-basket-refresh/#findComment-298244 Share on other sites More sharing options...
robgood Posted July 15, 2007 Author Share Posted July 15, 2007 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 https://forums.phpfreaks.com/topic/59943-basket-refresh/#findComment-298685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.