<?php
   session_start();
if(!isset($_session['passed']))
{
$_session['passed']=0;
}
echo   $_session['passed'];
echo   $_session['unm'] . "aa"; if ($_session['passed']==1)
{
exit();
}

if($_session['passed']==0) 
{
$unm=$_POST['unm'];
$upwd=$_POST['upwd'];
$chkpw=$_POST['chkpw'];
#echo $unm;
// if ($chkpw=="send")
     if($unm!="")
{
require "conf.php";
$connection=mysql_connect($host,$user,$pass) or die("unable to connect!");
mysql_select_db($db) or die("unable to select database "); $query1="select count(*) from czy where mc = '" . $unm . "' and mm='" . $upwd . "'"; $result=mysql_query($query1) or die("error sql to exec");   
$row=mysql_fetch_row($result);
#echo $query1;
if ($row[0]>0)
{
$_session['passed']=1;
$_session['unm']=$unm;
$unm="";
echo   $_session['passed'];
echo   $_session['unm'];
mysql_free_result($result);
#print "<BR><BR><BR><BR><BR><BR><div align=center>登录成功,系统将自动返回,或点击<a href='index.php'>这里</a>立即返回</div>";
#print '<meta http-equiv="refresh" content="0;URL=index.php">';
#header("Location: index.php"); 
exit("");
}
else
{
$Errmsg="用户名或密码不正确";
mysql_free_result($result);
}
}
}   if(!$_session['passed'])
{  
?>
<html>
<head>
<script type="text/javascript" language="JavaScript1.2" src="js\menu.js"></script>
</head>
<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr>
<td><script type="text/javascript" language="JavaScript1.2" src="js\top.js"></script>
</td>
  </tr>
</table>
<script language="javascript">
function CheckForm()
{
if(document.form1.unm.value=='')
{
alert('\n请输入用户名!\n');
document.form1.unm.focus();
return false;
}
if(document.form1.upwd.value=='')
{
alert('\n请输入密码!\n');
document.form1.upwd.focus();
return false;
}
}
</script>
<table width="1000" align="center" border="0" cellspacing="1" cellpadding="0">
  <tr>
    <td width="500" colspan="2"><?PHP echo($Errmsg); ?></td><?php echo $query1; ?>
  </tr>
  <form id="form1" name="form1" method="POST" action="<?PHP $_SERVER['PHP_SELF'] ?>" onsubmit="return CheckForm();">
  <tr>
    <td width="80">用户名:</td>
    <td width="417">
      <!-- <input type="text" name="unm"> -->
  <SELECT NAME="unm">
 <?php
require "conf.php";
$connection=mysql_connect($host,$user,$pass) or die("unable to connect!");
mysql_select_db($db) or die("unable to select database ");    $query1="select mc from czy"; $result=mysql_query($query1) or die("error sql to exec");
  if (mysql_num_rows($result)>0 )
  {
   while ( $row=mysql_fetch_row($result))
{
echo "<option value=" . $row[0] . ">" . $row[0] . "</option>";
}
  }
  else
  
  {
  echo "no rows found !";
  }
  mysql_free_result($result);
 ?>   
  
  </SELECT>
    </td>
  </tr>
  <tr>
    <td>密 码:</td>
    <td><input type="password" name="upwd"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value=" 登录 ">
      <input type="hidden" name="chkpw" value="send">
    <input type="button" name="Submit2" value=" 关闭 " onclick="self.close()"></td>
  </tr>    
  </form></table>
</HTML>
<?PHP
exit("");
}
?>比方登录admin,密码1111正确后,打印出来是0aa   1admin 请问为什么

解决方案 »

  1.   

    $_session['passed']=1; 
    $_session['unm']=$unm; 
     你这里把值改变了
      

  2.   

    如果其他页调用的时候,出错用户名和密码会不能继续且有提示,但正确用户名和密码后仍然有登录的窗口出现echo $_session['unm'];
    echo $_session['passed'];
    include "userlogin.php";结果session打印出来为空,和session大小写有没有关系啊,还是其他原因
      

  3.   

    密码验证程序,是一个公用的程序,其他程序运行时需要检查有否正确登录,如果没有登录,如果已登录不再提示登录
    我贴的就是密码验证程序,其他程序中
    echo $_session['unm']; 
    echo $_session['passed']; 
    include "userlogin.php"; 是为了检查登录状况,怎么就不明白了呢
      

  4.   

    注意 大小写....$_SESSION['unm']$_SESSION['passed']
      

  5.   

    一个super global的预定义变量,小写出错了肯定是不成。
      

  6.   

    $_SESSION $_POST $_GET $_REQUEST 均只能为大写,这是PHP预定义变量
      

  7.   

    谢谢大家,我找到问题所在了,在php.ini 中,关于session.cookie的设置不对session.cookie_path =  "c:\windows\temp"应为session.cookie_path =  /