![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
testclass.php
<?
class Login
{
var $username; //用户名
function Login($username) { //构造函数
$this->username=$username;
}
function session() //置session
{
session_start();
$_SESSION['username']=$this->username; //给session变量赋值
//print $_SESSION['username'];exit();
}
}
?>
test.php
<?php
include("testclass.php");
$login=new Login('test');
$login->session();
//print $_SESSION['username'];exit();//这里是有session['username']的,但到test1.php就没了
header("Location: test1.php");
?>
test1.php
<?php
session_start();
if (session_is_registered('username')){
print "yes";
}
else{
print "no";
}
exit();
$test=$_SESSION['username'];
print $test;
exit();
?>
session是全局变量吧?但在类中注册的为什么会这样呢?在test.php中还是有的,但转到test1.php就没有了,谁知道为什么?
PS:小弟我初学PHP,很多都不懂,那位老大推荐本全面点的书来看看,最好有电子版,因为我是穷人嘻嘻

