dongshao4207 2016-06-15 22:39
浏览 47
已采纳

PHP会话在重定向上丢失一半

I have been working on this for awhile and can't seem to pin it down. Sessions are working I have session_start() at the top of each page that I access or set sessions.

First off I started with three sessions variables $_SESSION['id'], $_SESSION['user'] and $_SESSION['start'] to my login script and everything was working fine. I added two more sessions $_SESSION['patron'] and $_SESSION['business'].

$_SESSION['user'] = $user_info['email'];
$_SESSION['id'] =   $user_info['id'];
$_SESSION['patron'] = $user_info['patron'];
$_SESSION['business'] = $user_info['business'];
$_SESSION['start'] = time();
redirect_to('../page.php');

All sessions are set after login script is run and redirected fine, but I lose some of them when I redirect again leaving just the $_SESSION['user'], $_SESSION['start'] and $_SESSION['id'] sessions still set. I don't understand why only some are still set and the others are lost.

Another issue is that I changed the session $_SESSION['start'] name to $_SESSION['time'] and now that session is lost when I redirect after my login script has run.

Here is my redirect script:

function redirect_to($location = NULL) {
     if($location != NULL) {
        define('URL', 'http://www.website.com/');
          header('Location: ' .URL. $location);
        exit();
     }
}

Any suggestions will be appreciated.

  • 写回答

1条回答 默认 最新

  • dqroc48068 2016-06-16 00:20
    关注

    SOLVED!!!

    I've been working on this project for too long...I forgot that I had a function that purges sessions. It unsets sessions created by form submissions. I have an array that has session names to ignore and I left these out of it. So every time a page is refreshed, it unsets those sessions. I am so sorry for wasting your time. I completely forgot about it. I worked on that for about two hours....Lame.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题