PHP session 丢失 问题求助 急

jy00807290 2012-04-07 05:06:50
大家好,我在项目中 遇到一个十分离奇的SESSION丢失问题,有遇到这样问题的人帮我解答一下吗?

就是在HTML框架里面 页面跳转以后 我依然可以取到SESEION_ID
但是跳转以后同样的ID里面存入的信息就消失了,我用SMARTY在HTML里面循环的列表页条数 中第一条用跳转的方式,里面存如的信息永远不会丢失。但是到第二条以后 ,SESSION ID还在 但是 里面的所有存入的会员 会员权限等参数全部消失。
谁能给个寻找问题的方法 或者 查找出问题 思路吗?
...全文
668 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
jy00802036 2012-04-09
  • 打赏
  • 举报
回复
这里上 $_SESSION['aduid'] 等的 赋值代码 帮我看一下什么问题
<?php
session_start();
include '../includes/config.php';
$_session["admin"] = null;
$m = new mysql();
$m->open();
$user = trim($_POST["user"]);
$password = trim($_POST["password"]);
$yz = trim($_POST["yz"]);
//echo $yz;
if($yz == $_SESSION['checkcode'])
{
$sql = "select * from admin where adname= '$user' and adpassword = '$password'";
$m->get($sql);
if($m->getRows()){
$n = $m->getValue(0,'adname');
$j = $m->getValue(0,'adjurisdiction');
$add = $m->getValue(0,'aduid');
$_SESSION["admin"] = $n;
$_SESSION["jur"] = $j;
$_SESSION["aduid"] = $add;
$sid = session_id();
//echo $sid;
//echo $_SESSION["admin"];
header( "Location: ../member/index.php?sid={$sid}");
//$url = "./member/index.php";
//header("location:./member/index.php");


}else{
echo "<script type='text/javascript' charset=‘gb2312’>top.location='../templates/jump.html';</script>";
}

}else{
echo "<script type='text/javascript' charset=‘gb2312’>top.location='../templates/jump.html';</script>";
}
?>
xuzuning 2012-04-09
  • 打赏
  • 举报
回复
1、你的贴图中每个框架中都有 SID 出现,而且都相同。这就不是 session 丢失的问题了
你搞错了方向,自然也就找不出问题

2、虽然你在 echo $_SESSION['aduid']; 时出现错误
但你也没有给出对 $_SESSION['aduid'] 赋值的代码
jy00802036 2012-04-09
  • 打赏
  • 举报
回复
回复次数 到了 ~~~换个马甲 上来:
至于浏览器缓存的问题 我也看了。 从IE8 9到 FF 到谷歌都一样 ,本人 新手 但是 谷歌还是会用的,你们上面说的那些问题,我都检查了。问题我也查到了 就是我在列表页 进入内容页的时候传递了一个BOOK的ID参数,内容页接收这个参数没问题,但是这时候返回列表也SESSION 就丢失,所以只要内容页一有这个参数SESSION内容就丢失,当我把这个参数注释掉以后 返回列表页SESSION 就还在,是我代码写的不对?还是那里有问题,请大家指点一下
jy00807290 2012-04-09
  • 打赏
  • 举报
回复
列表页的代码
<?php
include '../includes/class_smarty.php';
include '../includes/config.php';
include_once('../wnpage/page.class.php');
session_start();
header("Cache-Control: private");
echo session_id();
echo "<p>++++++++++</p>";
echo $_SESSION['aduid'];
echo "<p>++++++++++</p>";
echo $_SESSION['jur'];
$m = new mysql();
$m->open();
mysql_query("set character_set_results=utf8");
$j = $_SESSION['jur'];
$add = $_SESSION['aduid'];
$date = date("Y-m-d h:i:s");
$data_count = 0;
$pageSize= 2;
if($add == 1){
$sql_cont = "select count(*) as c from book where bodel = 1 order by boid";
}else{
$sql_cont = "select count(*) as c from book where prid = $add and bodel = 1 order by boid";
}
$rs_cont = $m->get($sql_cont);
$data_count = mysql_result($rs_cont,0,'c');
$page_count = ceil($data_count/$pageSize);
$num = mysql_num_rows($rs_cont);
@$p = trim($_GET["page"]);
if($p=="")
{
$p = 1;
}
else
{
$p = (int)$p;
if($p<=0)
{
$p = 1;
}
elseif ($p>$page_count)
{
$p = $page_count;
}
}
$limit_page = ($p-1)*$pageSize;
switch($j){
case 1:
$sql = "SELECT book.boid,book.boname,publicationcategory.pcname,language.laname,book.bostatus,admin.adreporting_unit,book.time,admin.person,book.bodel FROM book, publicationcategory,language,admin WHERE (publicationcategory.pcid = book.pcid) and (book.prid = admin.aduid) and (book.laid = language.laid) and (book.bodel = 1) order by book.boid limit {$limit_page},{$pageSize}";
$rs = $m->get($sql);
break;
case 2:
$sql = "SELECT book.boid,book.boname,publicationcategory.pcname,language.laname,book.bostatus,admin.adreporting_unit,book.time,admin.person,book.bodel FROM book, publicationcategory,language,admin WHERE (book.prid = $add) and (publicationcategory.pcid = book.pcid) and (book.prid = admin.aduid) and (book.laid = language.laid) and (book.bodel = 1) order by book.boid limit {$limit_page},{$pageSize}";
$rs = $m->get($sql);
break;
}
$x = 0;
while($arr = mysql_fetch_array($rs)){
$list[]=array("boid"=>$arr['boid'],"boname"=>$arr['boname'],"pcname"=>$arr['pcname'],"laname"=>$arr['laname'],"bostatus"=>$arr['bostatus'],"unit"=>$arr['adreporting_unit'],"time"=>$arr['time'],"person"=>$arr['person']);
$bost = $list[$x]["bostatus"];
switch($bost){
case 0:

$bost = "未审核";
$list[$x]["bostatus"] = $bost;
break;
case 1:

$bost = "初审通过";
$list[$x]["bostatus"] = $bost;
break;
case 2:

$bost = "终审通过";
$list[$x]["bostatus"] = $bost;
break;
}
$x++;
}
//echo $_SERVER["HTTP_REFERER"];
//if(!$url){ $url=$_SERVER["REQUEST_URI"];}else{$url=$_SERVER["HTTP_REFERER"];}
$total=$data_count;
/*echo $pageSize."+++";
echo $total;*/
$b = new SmartyAissing;
$b->getArr();
if(!empty($list))
$b->getAissing("list",$list);
pageft($total,$pageSize,1,1,1,5);
$b->getAissing("pagenav",$pagenav);
$b->getWeb("archives.html");
?>


内容页的代码
<?php
session_start();
echo session_id();
include '../includes/class_smarty.php';
include '../includes/config.php';
include '../wnpage/page.class.php';
$m = new mysql();
$m->open();
mysql_query("set character_set_results=utf8");
$get = $_GET['bouid'];
$sql = "SELECT book.boid,book.boname,book.pcid,publicationcategory.pcname,book.bospecification,book.bowords,book.bobodyweight,book.boisbn,language.laname,book.boauthor,book.boprice,book.bocoverweight,book.bokc,bodycolornumber.bcname,book.bopublishdate,book.bosheet,binding.biname,book.bostatus,book.bointroduction,book.botag,book.boremark,book.boreason,book.bocoverpath,book.bocopyrightpath FROM book, publicationcategory,language,binding,bodycolornumber WHERE (publicationcategory.pcid = book.pcid) and (language.laid = book.laid) and (binding.biid = book.biid) and (bodycolornumber.bcid = book.bcid) and book.boid = $get ";
$rs = $m->get($sql);

$x = 0;
while($arr = mysql_fetch_array($rs)){
$list[]=array("boid"=>$arr['boid'],"boname"=>$arr['boname'],"pcid"=>$arr['pcid'],"pcname"=>$arr['pcname'],"bospecification"=>$arr['bospecification'],"bowords"=>$arr['bowords'],"bobodyweight"=>$arr['bobodyweight'],"boisbn"=>$arr['boisbn'],"laname"=>$arr['laname'],"boauthor"=>$arr['boauthor'],"boprice"=>$arr['boprice'],"bocoverweight"=>$arr['bocoverweight'],"bcname"=>$arr['bcname'],"bopublishdate"=>$arr['bopublishdate'],"bosheet"=>$arr['bosheet'],"biname"=>$arr['biname'],"bostatus"=>$arr['bostatus'],"bointroduction"=>$arr['bointroduction'],"botag"=>$arr['botag'],"boremark"=>$arr['boremark'],"boreason"=>$arr['boreason'],"bocoverpath"=>$arr['bocoverpath'],"bocopyrightpath"=>$arr['bocopyrightpath'],"bokc"=>$arr['bokc']);
$bost = $list[$x]["bostatus"];
switch($bost){
case 0:

$bost = "未审核";
$list[$x]["bostatus"] = $bost;
break;
case 1:

$bost = "初审通过";
$list[$x]["bostatus"] = $bost;
break;
case 2:

$bost = "终审通过";
$list[$x]["bostatus"] = $bost;
break;
}
$x++;
}
$sql_bi = "select * from binding order by biid asc";
$rs_bi = $m->get($sql_bi);

while($arr_bi = mysql_fetch_array($rs_bi)){
$list_bi[]=array("biid"=>$arr_bi['biid'],"biname"=>$arr_bi['biname']);
}

$sql_la = "select * from language order by laid asc";
$rs_la = $m->get($sql_la);

while($arr_la = mysql_fetch_array($rs_la)){
$list_la[]=array("laid"=>$arr_la['laid'],"laname"=>$arr_la['laname']);
}


$sql_pc = "select * from publicationcategory order by pcid asc";
$rs_pc = $m->get($sql_pc);

while($arr_pc = mysql_fetch_array($rs_pc)){
$list_pc[]=array("pcid"=>$arr_pc['pcid'],"pcname"=>$arr_pc['pcname']);
}

$sql_bc = "select * from bodycolornumber order by bcid asc";
$rs_bc = $m->get($sql_bc);

while($arr_bc = mysql_fetch_array($rs_bc)){
$list_bc[]=array("bcid"=>$arr_bc['bcid'],"bcname"=>$arr_bc['bcname']);
}
//echo $_SERVER["HTTP_REFERER"];
//if(!$url){ $url=$_SERVER["REQUEST_URI"];}else{$url=$_SERVER["HTTP_REFERER"];}
//$total=$data_count;
/*echo $pageSize."+++";
echo $total;*/
$b = new SmartyAissing;
$b->getArr();
if(!empty($list))
$b->getAissing("list",$list);
$b->getAissing("list_bi",$list_bi);
$b->getAissing("list_la",$list_la);
$b->getAissing("list_pc",$list_pc);
$b->getAissing("list_bc",$list_bc);
$b->getAissing("num",9);

$b->getWeb("a.html");
?>
jy00807290 2012-04-09
  • 打赏
  • 举报
回复

上面有SESSION ID 这是登录以后 的列表页


这是通过GET传递参数以后进入的内容页,上面也有SESSIO id



这是 通过返回列表页的 A标签点击返回后的内容SESSION ID 也在 但是 里面的JUR ADD等参数都消失了

下面我上 列表页 和 内容页的代码
jy00807290 2012-04-09
  • 打赏
  • 举报
回复
这样说吧 服务器没问题 整个SISSION_ID 我在所有页面都有 打开 ID号都是一样的 在列表页 首页 和框架的左侧的快捷入口 这些页面SIESSION的传递 都没问题 ,然后 我只要从列表页传递的GET数值进入 到 内容页 着时候传递的SESSION_id和里面的参数 也都在,但是我在这时候返回列表页的时候SESSION_ID还在 但是里面的所有参数都会丢失 我直接上图上代码
xjpphp 2012-04-09
  • 打赏
  • 举报
回复
你用什么方式存储session, 内存,磁盘,数据库,你的服务器怎么配置的?
huidengliu 2012-04-09
  • 打赏
  • 举报
回复
估计是客户端禁用cookie了吧
码无边 2012-04-09
  • 打赏
  • 举报
回复
浏览器缓存?你用的的什么浏览器???
jy00807290 2012-04-09
  • 打赏
  • 举报
回复
。。。。。顺便问一下 能QQ指点一下俺嘛? 我已经无奈到一定程度了,这是俺的第一个项目啊
jy00807290 2012-04-09
  • 打赏
  • 举报
回复
//$get = $_GET['bouid'];//注释 掉以后 不抱错~~~~这个 内容页接收的


而且这是注释掉 从内容页 返回列表页 不抱错 而且SESSION里面 JUR ADD等参数的赋值也都在,但是如果我不给内容页传递一个GET的数值,内容页根本没办法调用。我的列表页 的代码 我也检查了好多好多遍了 实在不看出来这一个赋值GET传递 为什么会和SESSION内的参数出问题
jy00807290 2012-04-09
  • 打赏
  • 举报
回复
<?php
session_start();
echo session_id();
include '../includes/class_smarty.php';
include '../includes/config.php';
include '../wnpage/page.class.php';
$m = new mysql();
$m->open();
mysql_query("set character_set_results=utf8");
//$get = $_GET['bouid'];//注释 掉以后 不抱错~~~~这个 内容页接收的
xuzuning 2012-04-09
  • 打赏
  • 举报
回复
$get = $_GET['bouid'];
$sql = "SELECT book.boid,book.boname,book.pcid,publicationcategory.pcname,book.bospecification,book.bowords,book.bobodyweight,book.boisbn,language.laname,book.boauthor,book.boprice,book.bocoverweight,book.bokc,bodycolornumber.bcname,book.bopublishdate,book.bosheet,binding.biname,book.bostatus,book.bointroduction,book.botag,book.boremark,book.boreason,book.bocoverpath,book.bocopyrightpath FROM book, publicationcategory,language,binding,bodycolornumber WHERE (publicationcategory.pcid = book.pcid) and (language.laid = book.laid) and (binding.biid = book.biid) and (bodycolornumber.bcid = book.bcid) and book.boid = $get ";

指这里,没有了 $get 不报错吗?
jy00802036 2012-04-09
  • 打赏
  • 举报
回复
刚吃饭去啦 不好意思~~~现在回答:是的 我从列表页 有一个A连接传递了GET参数 到内容页 就是BOOK.BOID 不是注释掉这个不报错 是我把内容页接受这个BOOK.BOID的get注释了 就不报错。。我是在想不明白 接受这个GET 和SESSION里面的内容能有什么冲突,这个BOOK.BOID 是INT类型的

因为 我要调用每本书的参数 这些都需要靠这个BOOK.BOID来调用。。。所以 这个不能少的
xuzuning 2012-04-09
  • 打赏
  • 举报
回复
与之对应的是 book.boid
注释掉不报错吗?

另外 book.boid 是什么类型的?
jy00802036 2012-04-09
  • 打赏
  • 举报
回复
...你好 我是你帮我回答问题的那个PHP 新手 问题我已经找到了 就是你看我贴的内容页代码前几行里面有一个$get = $_GET['bouid']; 这个传递BOOK参数的GET值,只要我把数值注释了,SESSION 里面存的信息就完全没问题,但是这是调用每个书的ID 我的内容页就要靠这个ID来调用这本书的其他参数的,不能不用GET传递啊,为什么多了一个GET以后在返回 列表页就 会出现我SESSION里面赋值消失的问题
xuzuning 2012-04-09
  • 打赏
  • 举报
回复
代码就不必再贴了,除非要你贴的时候再说

按你的描述,header( "Location: ../member/index.php?sid={$sid}"); 这句是一定会执行到的是吧
那么从此开始
另写一个程序文件

session_start();
$_SESSION["admin"] = $n; //具体的值你自己定,只要是合法的就行。下同
$_SESSION["jur"] = $j;
$_SESSION["aduid"] = $add;
$sid = session_id();
header( "Location: ../member/index.php?sid={$sid}");

按你网站处理的流程,逐次替换跳转的 url,直到出现正确响应的 url 为止。这个 url 前一个 url 就是出现问题的地方,认真检查一下就应该找到毛病
jy00802036 2012-04-09
  • 打赏
  • 举报
回复
因为上面的两个参数 是从 登录的表单 提交过来 ,如果没登录成功 会自动跳到一个JS的提示页面,登录成功后操作数据库,找到我要赋值的字段,然后赋值进去,后面的所有页面的操作只需要从被赋值的SESSION 里面的权限控制字段来判断 就可以。 我个人是这么想的,然后 也就是这有登录成功了才能被赋值。我上面发的图都是我登录成功以后 的 如果有需要 我可以把登录的HTML也发上来,不过那个只是一个FROM,里面还有一个SESSION 参数 是 验证码的。除了这里其他的地方一般用不到。所以也就没贴上来,如果有需要我就发。我知道,我这样说,算不算回答 确定赋值的问题。。。。有点着急 好不容易看到人帮忙,比较激动
  • 打赏
  • 举报
回复
这样的我问题我也遇到过了
xuzuning 2012-04-09
  • 打赏
  • 举报
回复
你的段代码中,要对 $_SESSION 赋值,需要有两个条件成立
你如何能确认 $_SESSION 就一定能被赋值的


加载更多回复(3)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧