【发布时间】:2020-06-26 23:55:57
【问题描述】:
我目前正在尝试通过会话传递多维数组,同时还能够动态地添加/删除它(这是一个愿望清单)。数组的索引将是我添加到数组中的项目的 ID。我尝试了序列化,使用变量而不是实际会话,但没有一个对我正常工作。
我的问题是我的数组不会从第 1 页传递到第 2 页。第 1 页是用户单击任何“添加到愿望清单”按钮时发生的情况
我在谷歌上搜索并写了类似的内容:
第 1 页:
session_start();
$_SESSION['wishlist'] = array();
$id = $_GET['id'];
$imageFileName = $_GET['ImageFileName'];
$title = urldecode($_GET['PictureName']);
$_SESSION['wishlist'][$id]=array("id"=>$id,"title"=>$title,"imageFileName"=>$imageFileName); // Here im making the multidimensional array
$_SESSION['wishlist'] = $_POST; //found this way on Stackoverflow
header('Location:view-wish-list.php'); //move to second page
第 2 页:尝试启动会话并打印出要测试的数组:
session_start();
var_dump($_SESSION['wishlist']);
Var Dump 给了我 array(0) { }
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
删除
$_SESSION['wishlist'] = $_POST;。您正在发出 GET 请求,而 $_POST 显然是空的。