我在login.php的有用
session_start();//启动会话
Session_register("userID");//创建会话变量
创建session对象。
我的session.php代码是
<?
session_start();
//检查userID是否被注册为session
if(!isset($_SESSION['userID']))
{
echo "<script>";
echo "alert(\"Please Sign in before\");";
echo "location.href=\"javascript: window.open(\'index.php\',\'_parent\')\";";
echo "</script>";
}
?>现在我是set2.php,将session.php作为外挂来控制用户有没有登入。可是在login.php显示到我已登入成功,但是跳转到set.php就弹出对话框说我没登入!
session_start();//启动会话
Session_register("userID");//创建会话变量
创建session对象。
我的session.php代码是
<?
session_start();
//检查userID是否被注册为session
if(!isset($_SESSION['userID']))
{
echo "<script>";
echo "alert(\"Please Sign in before\");";
echo "location.href=\"javascript: window.open(\'index.php\',\'_parent\')\";";
echo "</script>";
}
?>现在我是set2.php,将session.php作为外挂来控制用户有没有登入。可是在login.php显示到我已登入成功,但是跳转到set.php就弹出对话框说我没登入!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="smallwindow.css" rel="stylesheet" type="text/css" />
</head><body>
<div id="downbg">
<div id="upbg">
<p class="pc">Login</p>
<form method="post" name="webadress" action="login_process.php">
<p class="pcss">User ID : <input name="userID" type="text" /></p>
<p class="pcss">Password: <input name="password" type="password" /></p>
<p class="pc"><input name="reset" type="reset" value="reset" />
<input name="login" type="submit" value="login"/></p>
</form>
</div>
</div>
</body>
</html>
login_process.php代码
<?
include("db_conn.php");
include("randpass.php"); if($_POST[userID]=="")
{
echo "<script>";
echo "location.href=\"loginwrong4.html\";";
echo "</script>";
}
else
{
//取出用户表中是否有此用户
$SQLStr="select * from users where UserId='$userID'";
$res=mysql_query($SQLStr); //若有此用户
if(mysql_num_rows($res)>0)
{
$row=mysql_fetch_array($res);
//判断用户密码是否正确
if($row['PassWord']==$password)//密码正确
{
session_start();//启动会话
Session_register("userID");//创建会话变量 if($row[g_times]>0)
{
/*************判断用户是否已经完成了特定的步骤******************/
$SQLStr="select * from stepcontrol where UserId='$userID'";
$res=mysql_query($SQLStr);
if(mysql_num_rows($res)>0)
{
$row=mysql_fetch_array($res);
if($row['score']==null)
{
echo "<script>";
echo "location.href=\"tips2.html\";";
echo "</script>";
}
if($row['step2']==null)
{
echo "<script>";
echo "window.top.location.href=\"set3.php\";";
echo "</script>";
}
if($row['step2']==1)
{
echo "<script>";
echo "window.top.location.href=\"present.php\";";
echo "</script>";
}
}
else
{
$SQLins="insert into stepcontrol(UserId) values('$userID')";
mysql_query($SQLins); echo "<script>";
echo "location.href=\"tips2.html\";";
echo "</script>";
}
}
else
{
echo "<script>";
echo "location.href=\"loginwrong2.html\";";
echo "</script>";
}
}
else//密码错误
{
echo "<script>";
echo "location.href=\"loginwrong5.html\";";
echo "</script>";
}
}
else
{
echo "<script>";
echo "location.href=\"loginwrong1.html\";";
echo "</script>";
}
}
?>set2.php代码只有
<?
include("session.php");
?>其他的都是html代码
$_SESSION['userID']不行吗?
这个session问题在本地测试时并没有出现,在我把网站传上空间后就出现这个问题的
是上传到国外空间的