简体   繁体   English

PHP 如何在从购物车移动到登录用户时保留会话信息?

[英]PHP How do I keep session information when moving from Cart to Logged In user?

I am making my own custom PHP shopping cart.我正在制作自己的自定义 PHP 购物车。 The cart works, I can add products and check out with PayPal.购物车有效,我可以添加产品并使用 PayPal 结账。

However, now I have added a new element to the mix.但是,现在我在组合中添加了一个新元素。 I am trying to integrate the cart with php-login.net script, forcing users to login before they can view the cart and pay.我正在尝试将购物车与 php-login.net 脚本集成,强制用户在查看购物车和付款之前登录。

The login/register script works, but after logging in, when the user is returned to "view_cart.php" there are no products in the cart.登录/注册脚本有效,但登录后,当用户返回“view_cart.php”时,购物车中没有产品。

The flow is like this:流程是这样的:

"products.php" -> "login.php" -> "view_cart.php" -> "paypal.com" -> "process-payment.php" “products.php”->“login.php”->“view_cart.php”->“paypal.com”->“process-payment.php”

there is a session created at products.php, and it seems to be erased when the new session is created at login.php, so no products show when the user gets to view_cart.php...在products.php 上创建了一个会话,当在login.php 上创建新会话时它似乎被删除了,所以当用户访问view_cart.php 时没有产品显示......

Any ideas how i can make these sessions share?我有什么想法可以让这些会议分享吗? Thanks!谢谢!

Your cart should have an ID.您的购物车应该有一个 ID。

Get the ID of the cart before you go through the login process.在完成登录过程之前获取购物车的 ID。

Do the login process.执行登录过程。

Get the new session id获取新的会话 ID

Update your cart entry in the db with the new session id.使用新的会话 ID 更新数据库中的购物车条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM