页面之间的PHP会话变量更改 [英] PHP session variable changes between pages
问题描述
我有一个这样设置的会话变量:
I have a session variable that I set like this:
<?php
$token = md5(uniqid(rand(), true));
session_start();
$_SESSION['token'] = $token;
print $_SESSION['token'];
?>
然后在另一页上,我有这个:
Then on another page I have this:
<?php
session_start();
print $_SESSION['token'];
?>
问题在于它们不匹配.我得到两个完全不同的字符串. register_globals
已关闭.我确实注意到,当我将md5(....)
设置为常量字符串时,例如:md5('example')
,它可以按预期工作并且两个字符串匹配.但这没关系.对这里发生的事情有任何想法吗?
The problem is that they don't match. I get two completely different strings. register_globals
is off. I did notice that when I set md5(....)
to a constant string eg: md5('example')
that it works as expected and the two strings match. But that shouldn't matter. Any ideas on what's going on here?
Apache Acces日志:
Apache Acces Log:
127.0.0.1 - - [18/Sep/2010:17:46:09 -0500] "GET /index.php HTTP/1.1" 200 3182 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3"
127.0.0.1 - - [18/Sep/2010:17:46:09 -0500] "GET /style/style.css HTTP/1.1" 304 - "http://cmb.local:8888/index.php" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3"
127.0.0.1 - - [18/Sep/2010:17:46:09 -0500] "GET /js/signup.js HTTP/1.1" 304 - "http://cmb.local:8888/index.php" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3"
127.0.0.1 - - [18/Sep/2010:17:46:09 -0500] "GET /index.php HTTP/1.1" 200 3182 "http://cmb.local:8888/index.php" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3"
127.0.0.1 - - [18/Sep/2010:17:46:10 -0500] "GET /index.php HTTP/1.1" 200 3182 "http://cmb.local:8888/index.php" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3"
我不太确定该怎么读,但是在我看来我的文件(我认为是"/"的index.php)被调用了三次.我读对了吗?那里发生了什么事?
I'm not quite sure how to read that but it looks to me that my file (index.php which I assume is the '/') is being called three times. Am I reading that right? What's going on there?
推荐答案
完全是我的愚蠢错误.我那里有一些空的<img>
标记,这些标记引起了额外的请求. facepalm 抱歉,问题解决了.谢谢您的帮助!
Completely stupid mistake on my part. I had some empty <img>
tags in there that were causing the extra requests. facepalm Sorry everyone, problem solved. Thanks for your help!!
这篇关于页面之间的PHP会话变量更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!