Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 管理Mulipt用户的购物车会话_Php_Jsp - Fatal编程技术网

Php 管理Mulipt用户的购物车会话

Php 管理Mulipt用户的购物车会话,php,jsp,Php,Jsp,我创建了$u会话['cart']的购物车名称,并为用户创建了$u会话['user']。当我单击“添加到购物车”时,向所有用户显示相同的产品。我想知道如何将特定的用户id链接到购物车会话。我是php的初学者。请帮帮我 这是密码 if(isset($_SESSION["cart"])) { $item_array_id = array_column($_SESSION["cart"], "item_id"); if(!in_array($_GET['id'],

我创建了$u会话['cart']的购物车名称,并为用户创建了$u会话['user']。当我单击“添加到购物车”时,向所有用户显示相同的产品。我想知道如何将特定的用户id链接到购物车会话。我是php的初学者。请帮帮我

这是密码

if(isset($_SESSION["cart"]))
    {
       $item_array_id = array_column($_SESSION["cart"], "item_id");
        if(!in_array($_GET['id'], $item_array_id)){
            $count = count($_SESSION["cart"]);
            $item_array = array(
        'item_id' =>  $_GET['id'],
            'item_name' => $_POST['hidden_name'],
            'item_price' => $_POST['hidden_price'],
                'item_image' => $_POST['hidden_image']
       );
            $_SESSION["cart"][$count] = $item_array;

        }

    }
    else{
        $item_array = array(
        'item_id' =>  $_GET['id'],
            'item_image' => $_POST['hidden_image'],
            'item_name' => $_POST['hidden_name'],
            'item_price' => $_POST['hidden_price']

       );
        $_SESSION["cart"][0] = $item_array;

    }


}

这是由于未使用“session_start()”初始化唯一会话造成的。只需在使用会话之前添加这些内容,就可以了。

如果您使用的是php的默认会话设置,那么这是不可能的;会话对于访问者的浏览器会话是唯一的。你还在做什么,你也在使用数据库来存储购物车吗?不,我没有使用数据库。如何使所有用户的会话都是唯一的会话对于每个访问者来说都是唯一的,您无需为此做任何事情。那么我可以做些什么来解决此问题呢?我应该使用会话_start()吗对于每个页面,因为我已经在连接folderKK中使用了它,我会给我的连接folder在输出缓冲区之前有什么吗?因为如果在“会话_start()”之前发送一段数据,它将不会发送cookies,因此会话将无法工作。请解决我的问题,我必须在2天内提交此项目