사용자가 로그인하면 아무 것도 화면에 표시되지 않습니다 (오류보고 기능 켜짐).
마치 $_SESSION
이 맞지 않습니까?
<?php
include_once('../includes/connection.php');
if (isset($_SESSION['logged_in'])) {
?>
<html>
<head>
<title>wa</title>
<link rel="stylesheet" type="text/css" href="../assets/stylesheet.css">
</head>
<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>
<br />
<ol>
<li><a href="add.php">Add Article</a></li>
<li><a href="delete.php">Delete Article</a></li>
<li><a href="logout.php">Logout</a></li>
</ol>
</div>
</body>
</html>
<?php
} else {
if (isset($_POST['username'], $_POST['password'])) {
$username = $_POST['username'];
$password = md5($_POST['password']);
if (empty($username) or empty($password)) {
$error = 'All fields are required!';
}else {
$query = $pdo->prepare("SELECT * FROM users WHERE user_name = ? AND user_password =
?");
$query->bindValue(1, $username);
$query->bindValue(2, $password);
$query->execute();
$num = $query->rowCount();
if ($num == 1) {
$_SESSION['logged_in'] = true;
header('Location: index.php');
exit();
} else{
$error = 'Incorrect details!';
}
}
}
?>
<html>
<head>
<title>Visuality dashboard</title>
<link rel="stylesheet" type="text/css" href="../assets/stylesheet.css">
</head>
<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>
<br /><br />
<?php if (isset($error)) { ?>
<small style="color:#aa0000;"><?php echo $error; ?>
<br /><br />
<?php } ?>
<form action="index.php" method="post" autocomplete="off">
<input type="text" name="username" placeholder="något">
<input type="password" name="password" placeholder="något">
<input type="submit" value="Login" />
</div>
</body>
<footer>
</footer>
</html>
<?php
}
?>
session_start(); ? 결국 $ _SESSION 안에 데이터를 저장하는 방법은 무엇입니까? –
"session_start();"를 잊어 버린 것 같습니다. 첫 번째 줄 또는 코드 상단에 붙여 넣기 만하면됩니다. – beeef