我怎样才能让会话变量持续跨越标题重定向? [英] How can I get session variables to persist across header redirects?
问题描述
header(Location:./ content / user_dash.php); 我有 session_start();
在每一页的顶部。
我已经尝试过我的标题重定向 session_regenerate_id(true);
$ b
我已经在我的头文件之前和session_regenerate_id重定向之后尝试了 session_write_close();
我试过 exit(0);
和 die();
after我的头重定向;
我试过头(Location:./ content / user_dash.php?PHPSESSID =。session_id());
如果我包含结束页面,它可以工作(但我不能使用它),并且当我更改它以重定向我的变量时停止工作。我通过$ _SESSION通过foreach循环测试了它,并且在包含页面时打印,但不在重定向。
我有点拉我的头发因为我确实需要在重定向后使用会话变量。
文件结构:
index.php = submits login form => login_code.php =在设置session vars => user_dash.php后重定向echos vars并没有显示(空vars,如果语句要回显ifset)
I已删除重定向,甚至简单的超链接都不会将我的会话变量带到下一页。
$ b 实时HTTP标头:
* serverinfo * / login_code.php
POST * serverinfo * / login_code.php HTTP / 1.1
Host:server
User-Agent:Mozilla / 5.0(Windows NT 6.1; WOW64; rv:12.0)Gecko / 20100101 Firefox / 12.0
Accept:text / html,application / xhtml + xml,application / xml ; q = 0.9,* / *; q = 0.8
Accept-Language:en-us,en; q = 0.5
接受-Encoding:gzip,deflate
连接:keep-alive
引用者:* serverinfo *
Cookie:PHPSESSID = im7kid3isj1q9ft03a68s6d5i3
内容类型:application / x-www-form-urlencoded
Content-Length:29
username = user& password = pass
HTTP / 1.1 200 OK
Cache-Control:no-store,no-cache,must-revalidate,post -check = 0,pre-check = 0
Pragma:no-cache
Content-Type:text / html
过期时间:1981年11月19日星期四08:52:00 GMT
服务器:Microsoft-IIS / 7.5
X-Powered-By:PHP / 5.3.10,ASP.NET
日期:2012年5月3日,星期四16:24:54 GMT
Content-长度:159
------------------------------------------- ---------------
* serverinfo * / content / admin_dash.php
GET * serverinfo * / content / admin_dash.php HTTP / 1.1
主机:服务器
用户代理:Mozilla / 5.0(Windows NT 6.1; WOW64; rv:12.0)Gecko / 20100101 Firefox / 12.0
Accept:text / html,application / xhtml + xml,application / xml; q = 0.9,* / *; q = 0.8
Accept-Language:en -us,en; q = 0.5
Accept-Encoding:gzip,deflate
连接:keep-alive
Cookie:PHPSESSID = im7kid3isj1q9ft03a68s6d5i3
HTTP / 1.1 200 OK
Cache-Control:no-store,no-cache,must-revalidate,post-check = 0,pre-check = 0
Pragma:no-cache
Content-Type:text / html
过期时间:1981年11月19日星期四08:52:00 GMT
服务器:Microsoft-IIS / 7.5
X-Powered-By:PHP / 5.3.10,ASP.NET
日期:星期四,2012年05月03日16:24:54 GMT
内容长度:3474
您需要调试您的应用程序。
这对你来说可能是一个惊喜,但调试需要大部分程序员时间。所以,有时间去学习一些真正的程序员的工作。
header(Location:./ content / user_dash.php?。session_name()。=。session_id() );
与 session_write_close()
一起使用是最防弹的方式如果它仍然不能正常工作,那么就开始调试吧。
$ b
- 检查会话文件
- 检查cookie
- 检查ini设置
- 检查user_dash.php中的会话ID - 是否一样?
- 检查您是否真的失去了所有会话或可能只是一个变量
谢谢为ini设置。
我可以看到2个可疑人物
- session.use_only_cookies表示通过url发送SID将不起作用。重新检查会话cookie
- session.cache_expire 180 180太小。
和I可能会忽略一些,因为我没有为调试您的应用程序付费,我有我自己的工作要完成。
所以,我只是建议让所有设置都是默认设置,并且在你知道你在做什么之前不要触摸它们。
How can I get session variables to persist across header redirects?
My header redirect looks like this: header("Location:./content/user_dash.php");
I have session_start();
at the top of every page.
I have tried before my header redirect session_regenerate_id(true);
I have tried before my header and after session_regenerate_id redirect session_write_close();
I have tried exit(0);
and die();
after my header redirect;
I have tried header("Location:./content/user_dash.php?PHPSESSID=".session_id());
If I INCLUDE the end page it works (But I cannot use this) and when I change it to redirect my variables stop working. I tested this with a foreach loop through $_SESSION and it prints when INCLUDING the page, but doesn't on redirect.
I'm kinda pulling my hair out over this because I really do need to use session variables after redirects.
File Structure:
index.php = submits login form => login_code.php = redirects after setting session vars => user_dash.php echos vars and nothing shows (empty vars, if statement to echo if isset)
I have removed the redirects and even simple hyperlinks aren't carrying my session variables to the next page.
Live HTTP Header:
*serverinfo*/login_code.php
POST *serverinfo*/login_code.php HTTP/1.1
Host: server
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: *serverinfo*
Cookie: PHPSESSID=im7kid3isj1q9ft03a68s6d5i3
Content-Type: application/x-www-form-urlencoded
Content-Length: 29
username=user&password=pass
HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/html
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: PHP/5.3.10, ASP.NET
Date: Thu, 03 May 2012 16:24:54 GMT
Content-Length: 159
----------------------------------------------------------
*serverinfo*/content/admin_dash.php
GET *serverinfo*/content/admin_dash.php HTTP/1.1
Host: server
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: PHPSESSID=im7kid3isj1q9ft03a68s6d5i3
HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/html
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: PHP/5.3.10, ASP.NET
Date: Thu, 03 May 2012 16:24:54 GMT
Content-Length: 3474
You need to debug your application.
It could be a surprise for you, but debugging takes most of the programmers time. So, time to learn some of the real programmers job.
header("Location:./content/user_dash.php?".session_name()."=".session_id());
used along with session_write_close()
is a most bulletproof way
if it's still not working start debugging it.
- check the session file
- check the cookies
- check ini settings
- check session id in the user_dash.php - is it the same?
- check if you really lose all your session or may be just one variable
thank you for the ini settings. I can see 2 suspicious ones
- session.use_only_cookies On means sending SID via url will have no effect. check session cookies AGAIN
- session.cache_expire 180 180 is way too small.
and I may overlooked some as I got not paid for the debugging your app and I have my own job to be done. So, I'd just suggest to make all settings default and never touch them until you got to know what are you doing certainly
这篇关于我怎样才能让会话变量持续跨越标题重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!