Rumah > pembangunan bahagian belakang > tutorial php > php 页面跳转后session为空

php 页面跳转后session为空

WBOY
Lepaskan: 2016-06-23 14:06:22
asal
1939 orang telah melayarinya

生成SESSION   loginok.php

<?php session_start();if($_GET['action'] == "logout"){ unset($_SESSION['username']); unset($_SESSION['userid']); exit('注销成功!<a href="javascript:history.back(-1);">点击返回</a>'); } if(isset($_POST['submit']) == ""){ exit('非法访问!!'); } $username= htmlspecialchars(trim($_POST['username']));$pwd = MD5(trim($_POST['pwd']));include('conn.php');$mql="select userid from users where username ='$username' and pwd='$pwd' limit 1";  $check_user =mysql_query($mql,$conn);  if($result =mysql_fetch_array($check_user)){ $_SESSION['username']= $username; $_SESSION['userid'] = $result['$userid'];  echo $username.',欢迎到来!<a href="my.php">用户中心</a><br/>'; echo '<a href="index.php">点击进入主页</a>'; exit();}else{ echo '登陆失败!点击<a href="javascript:history.back(-1);">返回</a>'; } ?>
Salin selepas log masuk
[code=php
判断index.php登陆 注册";}else{ $username =$_SESSION['username']; echo $username.",欢迎到来注销"; echo $_SESSION['userid']; echo "登陆 注册";} [/code]两个文件放在同一目录下登陆后在loginok.php生成session但跳转到index.php后,无论如何都只显示登陆注册


回复讨论(解决方案)

重发一下,乱了
生成SESSION loginok.php

<?php session_start();if($_GET['action'] == "logout"){	unset($_SESSION['username']);	unset($_SESSION['userid']);	exit('注销成功!<a href="javascript:history.back(-1);">点击返回</a>');	}if(isset($_POST['submit']) == ""){	exit('非法访问!!');	}$username= htmlspecialchars(trim($_POST['username']));$pwd = MD5(trim($_POST['pwd']));include('conn.php');$mql="select userid from users where username ='$username' and pwd='$pwd' limit 1";  $check_user =mysql_query($mql,$conn);  if($result =mysql_fetch_array($check_user)){	$_SESSION['username']= $username;	$_SESSION['userid'] = $result['$userid'];		echo $username.',欢迎到来!<a href="my.php">用户中心</a><br/>';	echo '<a href="index.php">点击进入主页</a>';	exit();}else{	echo '登陆失败!点击<a href="javascript:history.back(-1);">返回</a>';	}?>
Salin selepas log masuk

判断index.php
<?php session_start();var_dump($_SESSION['userid']);if(! isset($_SESSION['userid'])){ echo "<a href='login.php'>登陆</a> <a href='zhuce.html'>注册</a>";}else{ 	$username =$_SESSION['username'];	echo $username.",欢迎到来<a href='loginok.php?action=logout'>注销</a>";	echo $_SESSION['userid']; 	echo "<a href='login.php'>登陆</a> <a href='zhuce.html'>注册</a>";}	
Salin selepas log masuk

两个文件放在同一目录下登陆后在loginok.php生成session但跳转到index.php后,无论如何都只显示登陆注册 

什么浏览器测试的,多个浏览器测试看看。

ie和搜狗都不行

firefox 和chrome 可以不

解决了,很简单24行   $_SESSION['userid'] = $result['$userid'];错了,还是百度知道好

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan