我正在尝试在重新加载页面后使用内部AJAX调用加载最后一个会话,但它会引发注意:使用$cat = $_SESSION['cat'];
时未定义的索引cat
但是当使用$cat = $_REQUEST['cat'];
时,它工作正常,但没有恢复会话。
categories.php
<?php
ini_set('display_errors', 1);
session_start();
if(isset($_SESSION['cat'])){
echo $_SESSION['cat'] ;
}
并在ajax: loadScat.php
<?php
ini_set('display_errors', 1);
session_start();
if(isset($_SESSION['cat'])){
echo $_SESSION['cat'] ;
}
$cat = $_SESSION['cat']; // here says undefined index cat!
我想恢复我用内部ajax调用点击的最后一个类别,我该怎么做,为什么它显示上面的错误?那么多......
答案 0 :(得分:0)
每次重新启动浏览器,因为它是会话变量
categories.php
<?php
session_start();
ini_set('display_errors', 1);
$_SESSION['cat'] = "Sample String";
if(isset($_SESSION['cat'])) {
echo $_SESSION['cat'] ;
} else {
$cat =" Your Session has not been set and this page is <b>categories.php</b>";
echo $cat;
}
ajax: loadScat.php
session_start();
ini_set('display_errors', 1);
if(isset($_SESSION['cat'])){
echo $_SESSION['cat'] ;
} else
{
$cat =" Your Session has not been set";
echo $cat;
}