所以我创建了一个登录表单,将变量传递给login.php
的login.php
<?php
{
require_once("db_const.php");
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * from patient_details WHERE email LIKE '{$email}' AND password LIKE '{$password}' LIMIT 1";
$result = $mysqli->query($sql);
$row=mysqli_fetch_array($result);
if (!$result->num_rows == 1) {
echo "<p>Invalid username/password combination</p>";
} else {
$_SESSION['email'] = $row['email'];
header('Location: dashboard.php');
}
}
?>
登录检查工作正常......但会话变量不起作用。所以我试着在login.php中回应它。它在那里工作..但它不适用于另一页。在这种情况下,dashboard.php
Dashboard.php
<?php
// page2.php
session_start();
echo 'Welcome to page #2<br />';
echo $_SESSION['email']; // green
?>