0

刚刚注意到,在使用用户名和密码登录后,我永远不会重定向到 welcome.php 页面,但它看起来输入被接受:(

有任何想法吗?错误是:没有这样的文件或目录

那是代码 index.php:

<?php
session_start();
ob_start();

include "functions.php";

$database = "/mnt/www/zzz/summer.db"; // Database name
$table = "login"; // Table name
$logged = ""; // Logged status
// Open database
$opendb = new SQLite3($database);
$finduser = "SELECT * FROM $table WHERE UserName='".$username."'";
$finduserandpass = "SELECT * FROM $table WHERE UserName = '".$username."' AND Password = '".$password."'";

if($_POST['submit'])
{
  $username = protect($_POST['username']);
  $password = protect($_POST['password']);
  if(!$username || !$password)
  {
        echo "Username and password are required!";
  }
  else
  {
        $results = $opendb->query($finduser) or die("Query error");
        // numColumns() is counting table row
    $count = $results->numColumns();
    if($count == 0)
    {
      echo "The ussername does not exist!";
    }
    else
    {
            $count = $results->numColumns();
      if($num == 0)
      {
        echo "Wrong password!";
      }
      else
      {

        $results2 = $opendb->query($finduserandpass) or die("Query error");
        $row = $finduserandpass->fetchArray(SQLITE3_ASSOC);
                if($row['E_mail'] == NULL)
                {
                    echo "Your account is not yet activated!";
                }
                else
        {

                    $_SESSION['$username'] = $logged;
                    echo "Welcome!";
                    $time = date($logged)+60;
                    //redirect to the welcome page
                    header('Location: welcome.php');
        }
      }
    }
  }
}

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>
Title of the document
</title>
<style type="text/css">
body {background-color:teal;}
</style>
</head>
<body>
<form action="login.php" method="post">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td>Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>

函数.php

<?php

function protect($mystring)
{
    $string = trim(strip_tags(addslashes($mystring)));
    return $mystring;
}

?>

欢迎.php

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>
Summer Project Control Panel
</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript">
</script>
</head>

<body>
<?php
session_start();
if(!$_SESSION['$username'])
{
    header("Location: index.php");
}
else
{
  $currentUser = $_SESSION['username'];
  $message = '<p>Welcome, ' . ucfirst($currentUser) . '!</p>';
  echo $message;
}
?>
</body>
</html>
4

3 回答 3

4

在发送标头之前不要回显或打印任何内容。尝试注释掉该行echo "Welcome!";

于 2012-04-08T15:42:24.920 回答
3

错误的密码位是因为您正在检查一个不存在的变量$num- 第一次出现在您的if语句中

我想你也numrows不想numcolumns- http://www.php.net/manual/en/function.sqlite-num-rows.php

最后,您需要echo在重定向之前删除该语句,这会给您带来问题,并且在您将它们发送到不同页面时无论如何用户都不会看到。

于 2012-04-08T16:12:29.077 回答
0

如果要重定向用户,请不要输出任何内容,否则重定向将不起作用。只需删除 echo 语句,它应该可以正常工作。

于 2014-03-07T05:05:06.717 回答