sessionA.php
<?php
session_start();
session_register("userid");
$userid="wang";
header("location:session2.php");
?>sessionB.php
<?php
session_start();
session_register("userid");
$userid="wang";
echo "<a href=session2.php target='_blank'>session2.php</a>";
?>session2.php:
<?php
session_start();
echo $userid;
?>
为什么sessionA.php不能传递,而sessionB.php能传递$userid的值到session2.php?????
<?php
session_start();
session_register("userid");
$userid="wang";
header("location:session2.php");
?>sessionB.php
<?php
session_start();
session_register("userid");
$userid="wang";
echo "<a href=session2.php target='_blank'>session2.php</a>";
?>session2.php:
<?php
session_start();
echo $userid;
?>
为什么sessionA.php不能传递,而sessionB.php能传递$userid的值到session2.php?????
windows2000advanced+apache/1.3.14,模块方式加载PHP4.06
http协议前面是http header,
比如什么cookie, session,语言,content-type等都是在这个头里的
当然还可以包含其他东西
头后面就是数据了,数据可能是html也可能是2进制的
根据头来判断sessionA.php实际上,只有一个http头的,这个头告诉浏览器重新定向到
session2.php
header函数修改了原来的http的头信息
所以服务器没有传递session信息
如果你想传递,需要不使用header函数,
修改为
sessionA.php
<?php
session_start();
session_register("userid");
$userid="wang";
?>
<html>
<head>
<meta http-equiv="refresh" content="0;URL=session2.php">
</head>
<body>
</body>
</html>
就可以了,同样可以实现哪个功能
Session不是通过header传递的!
当执行session_start()时,php建立一个sessionid
并作为cookie发送给浏览器,同时,在服务器端建立session的数据记录。
在http中cookie的设定,是与服务器端转向互斥的,
有转向,则cookies设定不成功。
如果不希望通过增加设定session的页面,可以利用客户端的js或者meta标记转向
我做的登陆程序就是先注册session,然后header到内容页面。一切都很正常呀
我试过你的程序,也是不能传递的,
我真是很奇怪,因为我的那个程序以前是曾经用过的,当然是可以正常运行的,
现在怎么就不行了?
主要是PHP.ini中有一项(我的是在302行):
register_globals = On我试了一下:
当register_globals = On时 程序正常显示.
当register_globals = Off时 程序就不正常了.
我的php.ini里默认就是
register_globals = On
设置情况如下:
;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;;;;; #### **** modified {variables_order = "EGPCS"
register_globals = On
register_argc_argv = Off
post_max_size = 4M
gpc_order = "GPC"; Magic quotes
magic_quotes_gpc = On
magic_quotes_sybase = Off
magic_quotes_runtime = Off;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;
; Note - track_vars is ALWAYS enabled as of PHP 4.0.3
;variables_order = "EGPCS" ; This directive describes the order in which PHP registers
; GET, POST, Cookie, Environment and Built-in variables (G, P,
; C, E & S respectively, often referred to as EGPCS or GPC).
; Registration is done from left to right, newer values override
; older values.
;register_globals = On ; Whether or not to register the EGPCS variables as global
; variables. You may want to turn this off if you don't want
; to clutter your scripts' global scope with user data. This makes
; most sense when coupled with track_vars - in which case you can
; access all of the GPC variables through the $HTTP_*_VARS[],
; variables.
; You should do your best to write your scripts so that they do
; not require register_globals to be on; Using form variables
; as globals can easily lead to possible security problems, if
; the code is not very well thought of.
;register_argc_argv = On ; This directive tells PHP whether to declare the argv&argc
; variables (that would contain the GET information). If you
; don't use these variables, you should turn it off for
; increased performance
;post_max_size = 8M ; Maximum size of POST data that PHP will accept.
;gpc_order = "GPC" ; This directive is deprecated. Use variables_order instead.; Magic quotes
;magic_quotes_gpc = On ; magic quotes for incoming GET/POST/Cookie data
;magic_quotes_runtime= Off ; magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
;magic_quotes_sybase = Off ; Use Sybase-style magic quotes (escape ' with '' instead of \');;;; #### **** }但不知道为什么就是不可用??
你看看[Session]段
session.save_path = ?????
????? 这里表示你的session存放的目录
你检查这个目录存在不存在今天我帮你测试的时候 搞了老半天也不懂是怎么回事.
突然就想到了.
我在那个目录下看到有session临时文件呢
session1.php:
<?php
session_start();
session_register("userid");
$userid="wang";
header("location:session2.php");
?>session2.php:
<?php
session_start();
echo $userid;
?>
页面一跳转,session就失效,但session文件还存在
当然,页首用了session_start();
session1.php:
<?php
session_start();
session_register("userid");
$userid="wang";
header("location: session2.php?".session.name()."=".session.id());
?>session2.php:
<?php
session_start();
echo $userid;
?>
这样就可以了,注意在location:的后边要有一个空格。