会话变量到期 [英] Session Variables Expiring

查看:62
本文介绍了会话变量到期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 MySQL 临时表来存储购物车内容的购物车应用程序.购物车表的每一行都保存了会话值以唯一标识该行.我正在使用以下方法设置初始值:

I have a shopping cart app using a temporary MySQL table to store cart contents. Each row of the cart table has the session value saved to uniquely identify that row. I'm setting the initial value using the following:

$session_id = session_id();

每次用户将商品添加到他们的购物车时,我都会运行查询来计算他们购物车中的产品数量并使用以下方法保存该值:

Each time a user adds an item to their cart, I run a query to count the number of products in their cart and save that value using the following:

$_SESSION["total_cart_products"] = $cart_total_products['total_cart_products'];

在网站上,通过传递$session_id 文件并拉取结果来查询cart 表,每次加载都会生成cart 页面.我在标题中显示了购物车产品总数,以便用户始终知道他们的购物车中有多少商品.

On the web site, the cart page is generated each time it is loaded by querying the cart table by passing the $session_id file and pulling the results. I'm displaying a the total cart products in the header so the user always knows how many items are their cart.

这一切都很好,只是购物车总产品会话以某种方式在 $session_id 之前到期.因为即使购物车总产品会话已过期并在标题中显示为 0,购物车页面仍然可以工作.

This all works great except that somehow the total cart products session is expiring before the $session_id. Because the cart page will still work even thought the total cart products session has expired and displaying 0 in the header.

我认为两个会议会同时结束,但事实并非如此.这一切我错过了什么?

I would think both sessions would end at the same time, but they are not. What am I missing with all this?

谢谢

布雷特

推荐答案

我从来没有找到我的问题的答案 - 为什么我的会话变量似乎超时,而主会话却没有.

I never found an answer for my question - why it appears my session variable is timing out but the main session is not.

我切换到使用 cookie 并在成功结帐时删除 cookie.

I switch things to use cookies and delete the cookie on successful checkout.

这篇关于会话变量到期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆