我的登录页面不工作


My login page is not working

我正在设计一个简单的登录页面,允许用户登录。但我无法登录。我已经在数据库中检查了我的数据,事实上,我还试图编辑数据库表的数据,但这对我也没有帮助。它告诉我的电子邮件或密码不正确。我不知道为什么会发生这种事。

这是我的代码,请帮我解决这个问题

<div class="header">
<a href="<?php echo $url_home; ?>"><img src="<?php echo    
$design; ?>/images/logo1.png" alt="Forum" style="float:right;" /></a>
 </div>
<div class="message">You have successfully been logged out.<br />
 <a href="<?php echo $url_home; ?>">Home</a></div>
       <?php
 }
 else
 {
     $ousername = '';
     if(isset($_POST['username'], $_POST['password']))
      {
    if(get_magic_quotes_gpc())
    {
        $ousername = stripslashes($_POST['username']);
        $username = mysql_real_escape_string(stripslashes 
    ($_POST['username']));
        $password = stripslashes($_POST['password']);
    }
    else
    {
        $username = mysql_real_escape_string($_POST 
      ['username']);
        $password = $_POST['password'];
    }
    $req = mysql_query('select password,id from users where  
     username="'.$username.'"');
    $dn = mysql_fetch_array($req);
    if($dn['password']==sha1($password) and mysql_num_row
           ($req)>0)
    {
        $form = false;
        $_SESSION['username'] = $_POST['username'];
        $_SESSION['userid'] = $dn['id'];
        if(isset($_POST['memorize']) and $_POST['memorize'] 
  =='yes')
        {
            $one_year = time()+(60*60*24*365);
            setcookie('username', $_POST['username'],  
 $one_year);
            setcookie('password', sha1($password),  
 $one_year);
        }
  ?>
  <!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=utf-
  8" />
    <link href="<?php echo $design; ?>/style.css" rel="stylesheet"  
   title="Style" />
    <title>Login</title>
</head>
<body>
    <div class="header">
        <a href="<?php echo $url_home; ?>"><img src="<?php echo  
  $design; ?>/images/logo1.png" alt="Forum" /></a>
    </div>
    <div class="message">You have successfully been logged.<br />
  <a href="<?php echo $url_home; ?>"><b>Click here to go to main  
  forum</b></a></div>
  <?php
    }
    else
    {
        $form = true;
        $message = 'The username or password you entered is  
   invalid.';
    }
}
else
{
    $form = true;
}
if($form)
{
    ?>

我建议您改为查看PHP的PDO。使用起来更容易、更安全。