<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blog</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<div class="top"><?php (isset($_POST['session_id'])) ? include_once "logout.php" : include_once "lgn.php"; ?></div>
<div class="center">
<div class="left">left</div>
<div class="content"><?php include_once "blog.php"; ?></div>
</div>
</div>
</body>
</html>
<?php
$login = htmlentities(trim($_POST['login']));
$password = md5(trim($_POST['password']));
if (isset($_POST['submit'])) {
include_once "db_connect.php";
include_once "config.php";
if (isset($login,$password)) {
$query = "SELECT * FROM users WHERE login="."'".$login."'";
$result = mysqli_query($con,$query);
$user = array();
while ($row = mysqli_fetch_array($result)) {
foreach ($row as $key => $value) {
if (!is_numeric($key)) {
$user[$key] = $value;
}
}
}
if (($login === $user['login']) && ($password === $user['password'])) {
setcookie('session_id', $user['id']);
setcookie('login', $user['login']);
}else{
echo "Such user doen't exist or login/password dosn't match. Please, check them twice and try again!";
}
}
}
?>
<div class="login">
<form action="" method="POST">
<table>
<tr>
<td><input type="text" name="login" placeholder="Login" value="<?php echo $_POST['login'] ?>"></td>
<td><input type="password" name="password" placeholder="Password"></td>
<td><input type="submit" name="submit"></td>
</tr>
</table>
</form>
</div>
<table>
<tr>
<td><?php echo "Welcome back, ".$_COOKIE['login']; ?></td>
<td><a href="<?php setcookie('session_id', ""); ?>">Log out</a></td>
</tr>
</table>
<?php
if (проверка данных выводить шаблон или заглолвки отправлять) {
что-то можно сделать тут еще. но только не echo,print или вывод какой либо
тут можете посылать ваши хидеры (session, cookie И так далее)
else {
тут выводите ваш html типа echo '<html>........</html>';
}
?>
1 <?php
2 header('...');
...
1
2 <?php
3 header('...');
...
1 <?php
2 header('...');
... ...
455 $a = 4;
456
457
---------------
конец документа
1 <?php
2 header('...');
... ...
455 $a = 4;
456 ?>
457
---------------
конец документа