PHP的SESSION无效,怎么都写入不进去,在别的文件就用的很好的。

WBOY
Release: 2016-06-23 14:02:55
Original
1524 people have browsed it

<?php	session_start();	if(isset($_POST['sub'])){		require "./config.php";		if($_POST['login_name']==$admin_name && $_POST['login_pwd']==$admin_pwd){			$_SESSION['login_status']=="oko";		}else{			echo "<font color='red'><b>帐号或密码错误!</b></font>";		}	}?><html>	<head>		<title>后台管理页面</title>	</head>	<body>		<?php			if($_SESSION['login_status']!="oko"){				var_dump($_SESSION['login_status']);//这个地方一直是NULL		?>		<form name="login" method="post" action="">			username:<input type="text" name="login_name" /><br/>			password:<input type="password" name="login_pwd" /><br/>			<input type="submit" name="sub" value="submit" />		</form>		<?php			}else{				echo "ll";			}		?>	</body></html>
Copy after login


代码如上,很简单,但是SESSION一直都写不进去,不知道到底是什么原因!!


回复讨论(解决方案)

$_SESSION['login_status'] ="oko";  //赋值是一个=号

你试一下把

修改后的代码

if(isset($_POST['sub'])){
require "./config.php";
if($_POST['login_name']==$admin_name  && $_POST['login_pwd']==$admin_pwd){
$_SESSION['login_status']="oko";//这个地方你多了个“=”
}else{
echo "帐号或密码错误!";
}
}else{
session_start();//session_start();运行一次就可以了,而且要放在代码的最前边
}
?>


后台管理页面


if($_SESSION['login_status']!="oko"){
var_dump($_SESSION['login_status']);//这个地方一直是NULL
?>

username:

password:



}else{
echo "ll";
var_dump($_SESSION['login_status']);//要这个地方就可以打印了
}
?>



$_SESSION['login_status']="oko";  //赋值是一个=号

==号错了

好吧,我承认我SB了。。。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template