刚刚注意到,在使用用户名和密码登录后,我永远不会重定向到 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>