在php mysql中建立登录注销会话时出现服务器错误

时间:2013-02-11 17:42:24

标签: php mysql

我从网站上获得了帮助,并使用了大部分代码。我理解了代码,但无法弄清楚错误。

// main_login.php

<html>
<title>User Login Form</title>
<head></head>
<body>
<form name="form1" method="post" action="newcheckLogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="80">Username</td>
<td width="6">:</td>
<td width="300"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td width="6">:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>

// newchecklogin.php-这用于检查用户和查询数据库。

    <?php
    include("config.php");
    session_start();
    #echo "Check Login\n";
    ?>
    <html>
    <head><title></title>
    <form name="form2" method="post" action="Logout.php">
    <p align="right">
    <input type="submit" name="Logout" id=Logout" >
    </p>
    </form>
    </head>
    </html>
    <?php
    $myusername=stripslashes(mysql_real_escape_string($_POST['myusername']));
    $mypassword=md5(stripslashes(mysql_real_escape_string($_POST['mypassword'])));
    $sql="select jobid from jobs where userID='$myusername'";
    echo "Hey ".$myusername." ";
    $result=mysql_query($sql) or die(mysql_error());
    $row=mysql_fetch_array($result);
    $active=$row['active'];
    if(mysql_num_rows($result)==1){
            echo "Username and password found";
            session_register("myusername");            
            $_SESSION['login_user']=$myusername;           
            header("location:welcome.php");
    }
    else{
            $error="Your login Name or Password is invalid";
    }
    ?>

//的welcome.php

<?php
include('lock.php');
include('newchecklogin.php');
?>
<body>
<h1>Hello <?php echo $login_session; ?></h1>
<?php
echo "<br>You have ".$mysql_num_rows($result)." jobs<br>";
echo "<table border=1 cellpadding=4><th>Job id</th><br>";
while ( $r = mysql_fetch_assoc($result) ) {
        echo "<tr><td>";
        echo $r['jobid']."</td></tr>";
}
echo "</table>";
?>
</body>

// lock.php

<?php
include('config.php');
session_start();
$user_check=$_Session['login_user'];
$ses_sql=mysql_query("select userID from jobs where userID='$user_check'");
$row=mysql_fetch_array($ses_sql);
$login_session=$row['userID'];
if(!isset($login_session)){
        header("Location:login.php");
}
?>

请帮助,如果有人可以再次向我解释如何设置会话,那将会很棒。

1 个答案:

答案 0 :(得分:0)

我认为问题在于,您已将lock.php文件命名为,并且在尝试登录后尝试重定向login.php