session问题!永远的痛呀!

tq85 tq85 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
看前面一个帖子的时候,有位大虾给了个英文!
If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

register_globals: important note:
Since PHP 4.2.0, the default value for the PHP directive register_globals is off. The PHP community encourages all to not rely on this directive but instead use other means, such as the superglobals.

Caution:
This registers a global variable. If you want to register a session variable from within a function, you need to make sure to make it global using the global keyword or the $GLOBALS[] array, or use the special session arrays as noted below.

Caution:
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().

看的眼晕,好象大意是说!新版本里面如果使用$_session建议不要使用
session_register(), session_is_registered(), and session_unregister().
中间那段是说如果global给disable的话这三个函数会出现问题的!

底下一个大虾讲的更明白!
"
应该在新版的php已经没必要用session_register了

直接对$_SESSION["foo"]进行赋值/取值就可以了,和asp中一样。
"
如获至宝!正好我写的登陆程序始终有问题!
写了一个测试
first.php
<form action="login.php" method="post">
<p>用户名:
<input name="username" type="text" id="username">
</p>
<p>
<input type="submit" name="Submit" value="提交">
</p>
</form>
login.php
<?php
session_start();
$_SESSION['username']=$_POST['username'];
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<?php echo $_SESSION['username'];?>
</body>
</html>

2.php

<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<?php echo $_SESSION['username'];?>
</body>
</html>

这个工作的很好,session实现的传递!

可是正式又写一个的时候出问题了!
login.php
<?php
session_start();
?>
<?php require("userconfig.php");?>
<?php

if(empty($_POST['username'])||empty($_POST['password'])||empty($_POST['usertype'])) echo "error";
else
{
if($_POST['usertype']==0) $file=$companyfile;
else $file=$studentfile;
$userfile=$datapath.$file;
//echo $userfile;
$arr_row=file($data_file);
if($arr_row)
{
$num=count($arr_row);
for($i=0;$i<$num;$i++)
{
list($username,$password,$email)=explode("|",$arr_row[$i]);
if($username==$_POST['username']&&$password==$_POST['password'])
{
$_SESSION['user_name']=$username;
//$loginsatus=1;
break;
}
}
if(!empty($_SESSION['user_name']))
{
echo $_SESSION['user_name'];

}
else
{
echo "没有登陆成功";

}
}
}
?>

我一登陆就出现空白页!
而且我还可以在定义session之前echo
我前面注释掉的那个
//echo $userfile;
可以输出不报错!不清楚怎么回事,请大虾帮助!
我前面试过用那种传统的
session_register($username);
可也是出现空白页的!
...全文

相关推荐

验证码的session问题

http://bbs.csdn.net/topics/391829648 对应下载

jhlong12345

【企业管理】【管理科学】第一百零四篇 解决方案部的工作内容和工作职责01

产品报价是销售过程中价值变现的“临门一脚”,也是检验前期所有价值沟通成果的“试金石”。本体系旨在超越“价格告知”的初级层面,构建一个将价格与价值深度捆绑、引导客户决策、最大化赢单率与利润空间的战略性报价操作系统。它使报价成为价值沟通的延续、竞争定位的宣告和长期合作关系的开端,而非谈判对抗的起点。工程服务报价是专业服务销售皇冠上的明珠,其本质是将无形的专业智慧、不确定性的交付过程与可变的风险,转化为一份客户认可、权责清晰、商业可行的“价值交付契约”。本体系旨在构建一个超越简单“工时×单价”的初级模式,通过。

flyair_China

Discuz!X中SESSION机制实例详解

本文实例讲述了Discuz!X中SESSION机制。分享给大家供大家参考。具体如下: 在Discuz! X中一如继往的,SESSION 并没有使用 PHP 自带的 SESSION 机制,而是系统的一套自带的机制。 在数据库中可以看到有两个 SESSION 表: 一个是pre_common_adminsession,是管理员登录后台的 SESSION 表; 另一个是 pre_common_session 表,是所有用户在前台浏览页面时的 SESSION 表。 这两个表都是内存表(内存表的读写速度远高于 MYISAM 表及文本文件)。 在 Discuz! X 中 SESSION 与 COOKIE

weixin_38560107

解决springboot实现跨域session共享问题

解决springboot实现跨域session共享问题,防止sql注入。可以更有效的解决token问题,欢迎下载,有问题可以再评论下方留言,及时解答!!加群:687942640

JAVA叶知秋

nginx反向代理导致session失效的问题解决

主要介绍了nginx反向代理导致session失效的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

weixin_38686231
评论 3
收藏 已收藏
分享
返回顶部
tq85
基础编程 21,889 成员 140,329 内容