您需要附上您的 if 语句块,如下所示:
if($_POST['submit']) {
$hour = time() + 3600;
setcookie('username', $_POST['username'], $hour,'/');
setcookie('password', $_POST['pass'], $hour,'/');
header("Location: tutorhomepage.php");
}
此外,您需要在上述段之后移动连接等部分。
<?php
if($_POST['submit']){
$hour = time() + 3600;
setcookie('username', $_POST['username'], $hour,'/');
setcookie('password', $_POST['pass'], $hour,'/');
header("Location: tutorhomepage.php");
}
//------ server and mysql connection
$connection = mysql_connect('mywebsite', 'username', 'password') or die('Unable to connect');
mysql_select_db('myDB') or die('unbable to select DB');
//------log in cookie check
if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
$pass = $_COOKIE['password'];
$check = mysql_query("SELECT * FROM tutors WHERE username = '$username'") or die(mysql_error());
while ($info = mysql_fetch_row($check)) {
if ($pass != $info[1]) {
} else {
header("Location: /tutorhomepage.php");
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body><?php
//------- if form is submitted
if (isset($_POST['submit'])) {
// check if the user enetered login details
if (!$_POST['username'] | !$_POST['pass']) {
die('You must enter the required data.');
}
// and so on