会话 ID 值更改 [英] session id value changes

查看:39
本文介绍了会话 ID 值更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 PHP 网站.我有一个 $_SESSION['id'] 保存用户的用户名 ID,稍后我将在我的脚本中使用这个值.但是,当我浏览网站时,我注意到 ID 会发生变化.

I am writing a PHP website. I have a $_SESSION['id'] that hold the username id of a user, which I will use this value later on in my scripting. However, I notice that the ID changes as I surf the site.

id 是否以任何方式保留?或者,我应该将 id 更改为其他内容吗?

Is id reserved in any way? Or, should I change id to something else?

每当我多次单击按钮时就会发生此问题.我 100% 确定我不会在初始登录后更改 $_SESSION['id'].

This problem is happening whenever I click on a button several times. I am 100% sure that I'm not altering $_SESSION['id'] beyond the initial login.

有人可以帮助我了解发生了什么,以及如何修复.

Could someone please help me understand what is happening, and how it can be fixed.

推荐答案

我假设你已经使用了 session_start,如果没有看到其他评论 :P

I am going to assume you already use session_start, if not see the other comments :P

如果您启用了注册全局变量,则在您的代码中使用变量 $id 时,您可能会看到类似的行为.作为测试,请尝试:

If you have register globals on, you may be seeing behavior like that if you use the variable $id in your code. As a test, try:

<?php
session_start();
$_SESSION['testing'] = 'Foo';
$testing = 'bar';
die($_SESSION['testing']);
?>

重新加载页面几次.如果打印的是 bar 而不是 Foo,那可能是你的问题.您可能希望将会话变量命名为不太可能在其他地方使用的名称,或者(更正确)关闭注册全局变量.

Reload the page a couple times. If bar prints out rather than Foo, that may be your problem. You'll probably want to make the session variable name something that is less likely to get used elsewhere, or (more correct) turn off register globals.

这篇关于会话 ID 值更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆