加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 会话变量似乎没有保存

发布时间:2020-12-13 18:08:43 所属栏目:PHP教程 来源:网络整理
导读:相当简单的代码: ?session_start();$_SESSION['t'.time()] = "ok";echo "pre".print_r($_SESSION,1)."/pre";? 像预期的那样显示出类似的东西 Array( [t1330966834] = ok [t1330966835] = ok [t1330966836] = ok) 3页重新加载后. 我们改变几个符号: $_SESSI
相当简单的代码:
<?
session_start();
$_SESSION['t'.time()]     = "ok";
echo "<pre>".print_r($_SESSION,1)."</pre>";
?>

像预期的那样显示出类似的东西

Array
(
    [t1330966834] => ok
    [t1330966835] => ok
    [t1330966836] => ok
)

3页重新加载后.

我们改变几个符号:

$_SESSION[time()]     = "ok";

(现在没有“t”)我希望在重新加载之后会有类似的东西

Array
(
    [t1330966834] => ok
    [t1330966835] => ok
    [t1330966836] => ok
    [1330967020] => ok
    [1330967021] => ok
    [1330967022] => ok
    [1330967023] => ok
)

但实际上结果完全不同:

Array
    (
        [t1330966834] => ok
        [t1330966835] => ok
        [t1330966836] => ok
        [1330967020] => ok
    )

我们有3个先前的阵列单元格,只有一个“时间”单元格 – 无论您重新加载页面多少次.时间是正确的,它每秒都不同但只有一个没有’t’的细胞!
我也试过了

$t =time();
$_SESSION[$t]     = "ok";

乃至

$t =intval(time());
$_SESSION[$t]     = "ok";

但它仍然只有一个细胞随着时间的推移.

在两台不同的服务器上测试了php 5.2.13和5.3.10.
我究竟做错了什么?

The keys in the $_SESSION associative array are subject to the same limitations as regular variable names in PHP,i.e. they cannot start with a number and must start with a letter or underscore. For more details see the section on variables in this manual.

http://php.net/manual/en/session.examples.basic.php

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读