visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: session data


By: collegeBoy U.S.A.  Date: 19/09/2003 00:00:00  English  Points: 75 Status: Answered
Quality : Excellent
This isn't working in Netscape, it's not holding on to the sessions data:

--------------------------------
<?
include ('WBCat_fns.php');
// The shopping cart needs sessions, so start one
session_start();

if($new)
{
//new item selected
if(!session_is_registered("cart"))
{
$cart = array();
session_register("cart");
$items = 0;
session_register("items");
$total_price = "0.00";
session_register("total_price");
}
if($cart[$new])
$cart[$new]++;
else
$cart[$new] = 1;
$total_price = calculate_price($cart);
$items = calculate_items($cart);

}
if($save)
{
foreach ($cart as $beadid => $qty)
{
if($beadid=="0")
unset($cart[$beadid]);
else
$cart[$beadid] = $beadid;
}
$total_price = calculate_price($cart);
$items = calculate_items($cart);
}

do_html_header("Your shopping cart");

if($cart&&array_count_values($cart))
display_cart($cart);
else
{
echo "<p>There are no items in your cart";
echo "<hr>";
}
$target = "index.php";

// if we have just added an item to the cart, continue shopping in that category
if($new)
{
$details = get_bead_details($new);
if($details["makeid"])
$target = "show_make.php?makeid=".$details["makeid"];
}
display_button($target, "continue-shopping", "Continue Shopping");
$path = $PHP_SELF;
$path = str_replace("show_cart.php", "", $path);
display_button("checkout.php", "go-to-checkout", "Go To Checkout");
do_html_footer();
?>
--------------------------------

Can you see any reason why not?
By: LornaJane Date: 19/09/2003 01:27:00 English  Type : Answer
are you having a problem with cookies? Or are you using a newish version of PHP? Since 4.2 (or thereabouts - someone will correct me I'm sure), the way you refer to session variables has changed (actually a setting called register_globals changed in php.ini). To access a variable registered with a session you should now use $_SESSION['var'] rather than just $var. So you may well find that the browser does have the info, but you can't access it.

While I'm on the subject, register_globals off also means you should use $_SERVER['PHP_SELF'] rather than $PHP_SELF

Hope that helps, if I'm barking up the wrong tree, post back. Especially if it works in other browsers than netscape...
By: VGR Date: 19/09/2003 17:16:00 English  Type : Assist
agree with all possibilities.

Also look in the "security settings" of NS

and also try with Mozilla Firebird, it's the perfect tool to debug a (D)HTML page
By: collegeBoy Date: 19/09/2003 18:08:00 English  Type : Comment
So on the output_fns.php page I would change it from:

--------------------------------
<?

function do_html_header($title = '')
{
// print an HTML header

// declare the session variables we want access to inside the function
global $total_price;
global $items;
if(!$items) $items = "0";
if(!$total_price) $total_price = "0.00";

?>
--------------------------------

to:

--------------------------------
<?

function do_html_header($title = '')
{
// print an HTML header

// declare the session variables we want access to inside the function
global $_SESSION['total_price'];
global $_SESSION['items'];
if(!$items) $items = "0";
if(!$total_price) $total_price = "0.00";

?>
--------------------------------

Or do you mean elsewhere?

I attempted var_dump($_SESSION); and it produced nothing on the page at all. I viewed source and I logged into to my PHP error logs and there was no data. I checked security sessions but I accept cookies. It doesn't seem to be generating a cookie - so how is it holding the session? The other thing is that I find that it works on almost no body's pc but mine and only in IE on my pc, oh and Opera. I had a friend in NYC and she had the same results as me. It worked in IE for her but not in Netscape - however no one else can get this to hold the sessions that I've talked to and I went next door and used their pc and no, it doesn't work in IE there either. I'm completely befuddled.
By: VGR Date: 19/09/2003 18:42:00 English  Type : Assist
absolutely. Of the "superglobals" that are in fact super-under-globals, only one is really global. The other ones need to be declared as GLOBAL in the scope of a function

thus do :
function ttt() {
GLOBAL $_GET, $_POST;
//code
}

if you need to access (I never had this case) the $_REQUEST[] data from inside a function
By: collegeBoy Date: 20/09/2003 11:42:00 English  Type : Comment
Hmmm

"This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS."
By: VGR Date: 21/09/2003 18:09:00 English  Type : Comment
yes, as I said, only one ($_SESSION) is really global. This is said in the Manual. The other ones ARE NOT "available in all scopes", as they need to be declared GLOBAL inside a function's scope...
By: m_e_brown Date: 22/09/2003 20:32:00 English  Type : Comment
dont forget to put


session_start();
header("Cache-control: private"); //IE 6 Fix

at the top
By: collegeBoy Date: 24/09/2003 06:26:00 English  Type : Comment
Thanks guys =)
By: VGR Date: 24/09/2003 06:35:00 English  Type : Comment
thanks to you 8-)

Do register to be able to answer

EContact
browser fav
page generated in 349.900960 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page