Home > Backend Development > PHP Tutorial > 急!session问题

急!session问题

WBOY
Release: 2016-06-23 14:21:25
Original
800 people have browsed it

session url php

RewriteRule ^index.html&fun=000$ gyjw/check.php重写了url
我的登陆页面
<?php	session_start();	//使用session存储用户信息	if(isset($_POST["username"]))	{		$ss_user_id="";				//利用User累的IsValid()方法判断所输入的用户名和口令是否正确		require_once("user/UserClass.php");		$user=new User();		//如果正确,转到系统首页		if($user->IsValid($_POST["username"],$_POST["password"],$ss_user_id))		{			$_SESSION["ss_user_id"]=$ss_user_id;			echo "<script language='javascript'>";			echo " location='index.html';";			echo "</script>";		}		//如果不正确,转到登陆页面		else		{			echo "<script language='javascript'>";			echo " alert('用户名或密码错误');";      		echo "</script>";		}	}?>
Copy after login
主页的php
<?php	include 'http://localhost/gyjw/index.html&fun=000';?>//省略html部分
Copy after login
check.php
<?php  	if(! isset($_SESSION['ss_user_id']))	{   		echo "<script language='javascript'>";		echo "alert('您的用户无权进行此操作!');";		echo "top.location='login.html';";		echo "</script>"; 		exit;  	}?>
Copy after login
问题是登陆成功跳转至主页的时候,先跳转至check.php,之直接就显示了'您的用户无权进行此操作!',说明$_SESSION['ss_user_id']不存在了。然后如果修改了主页的php
<?php	include ("check.php");?>
Copy after login
就存在这个$_SESSION['ss_user_id']正常显示了主页内容。
麻烦各位大侠帮助解决!

回复讨论(解决方案)

check.php 中缺少 session_start();

check.php 中缺少 session_start();
呃,不小心删掉了,但不是这个问题。

check.php 中缺少 session_start(); 通过观察生成的session文件sess_...我发现如果include里面用的是check.php,就只会生成一个sess_,如果include里面放的http://localhost/gyjw/index.html&fun=000,就会生成两个sess_,其中一个是没有数据的,这是不是说明在跳转http://localhost/gyjw/index.html&fun=000的时候系统又重新生成了一个sess_,所以$_SESSION['ss_user_id']才没有值,要怎么解决呢?

Related labels:
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