并非所有PHP会话都已保存

时间:2014-07-08 12:47:34

标签: php session

我遇到了这个问题。在我的PHP代码中,我设置了两个会话:Cart和Visited。 购物车很清楚,访问过的是查看最新访问产品的功能。

我的购物车有这个数组:

Partnr
Productname
Quantity
Productgroep
Subgroup

Visited有这个数组:

Partnr
Productname
Description
Productgroup
Subgroup

购物车的会话存储正确,但访问的不是。

这是购物车的代码:

$_SESSION['cart'][] = array('quantity' => $_POST['quantity'],
    'partnr' => $_POST['partnr'],
    'hoofdgroep' => $_POST['hoofdgroep'],
    'subgroep' => $_POST['subgroep'],
    'productname' => $_POST['productname']
);

访问的代码:

$addition = array('productcode' => $csv[1][1],
    'productname' => $csv[1][2],
    'description' => $csv[1][4],
    'hoofdgroep' => $_GET['hoofdgroep'],
    'subgroep' => $_GET['subgroep']);
$_SESSION['visited'][] = $addition;

有谁知道为什么我的访问将不会被保存并且购物车已保存?

更新: 在显示$_SESSION['visited']

的3个产品后访问了会话
Array
(
    [0] => Array
        (
            [productcode] => AD-HPR-150-CR50
            [productname] => SimpleXMLElement Object
                (
                    [0] => Adapterring voor HPR-150
                )

            [description] => SimpleXMLElement Object
                (
                    [0] => Adaptar
                )

            [hoofdgroep] => lighting
            [subgroep] => accessoires
        )

)

我的购物车会话中包含三个产品$_SESSION['cart']

Array
(
    [0] => Array
        (
            [quantity] => 1
            [partnr] => AD-HPR-150-CR50
            [hoofdgroep] => lighting
            [subgroep] => accessoires
            [productname] => Adapterring voor HPR-150
        )

    [1] => Array
        (
            [quantity] => 1
            [partnr] => AD-HPR-150-CR50
            [hoofdgroep] => lighting
            [subgroep] => accessoires
            [productname] => Adapterring voor HPR-150
        )

    [2] => Array
        (
            [quantity] => 1
            [partnr] => HP-CDT1006B-24
            [hoofdgroep] => lighting
            [subgroep] => diffuselite-dome
            [productname] => HighPower 45inch Compact Diffused Tube Light (with inline dimmer 10 turn locking knob) Blue, 24VDC
        )

)

更新2: 修改后的代码:

$addition = array('productcode' => $csv[1][1],
    'productname' => (string)$csv[1][2],
    'description' => (string)$csv[1][4],
    'hoofdgroep' => $_GET['hoofdgroep'],
    'subgroep' => $_GET['subgroep']);
$_SESSION['visited'][] = $addition;

0 个答案:

没有答案