I just made a site that allows CMS so our client can login and modify the content to their liking. In the localhost and on a test server that we have works fine but at the destination final server I can not get out of the login page after filling in with the correct details.
There are 2 possible outcomes submit :
- stay on form page
- and if it's all right it makes
redirect
into the menu.
But it does not redirect
and none of the validation messages also appear. I went to the browser console and the only difference I saw between the servers is in the response header where it is connection: close
and in others (where it works correctly) is connection: Keep-Alive
. Is this?
I've done a lot of research and can not find any clear answers to help me solve this problem.
I've even tried to implement header("Connection: Keep-Alive");
in the code but the problem remains, although the response header is now connection: Keep-Alive, close
. I also used var_dump
on localhost array(1) { ["logged_in"]=> bool(true) }
appears. On the final server array(0) { }
appears the session is not being started. I do not understand why.
<?php
session_start();
var_dump($_SESSION);
header("Connection: Keep-Alive");
header('Content-type: text/html; charset=UTF-8');
include_once('../includes/connection.php');
if(isset($_SESSION['logged_in'])) { ?>
<html>
<head>
<meta charset="UTF-8" />
<title>AdminPT</title>
<link rel ="stylesheet" href="../assets/style.css"/>
</head>
<body>
<div class="container">
CMS - PT
<br>
<ol>
<li><a href ="add.php">Adicionar Artigo</a></li>
<li><a href ="delete.php">Eliminar Artigo</a></li>
<li><a href ="logout.php">Sair</a></li>
</ol>
</div>
</body>
</html>
<?php
}
else {
//display login
if(isset($_POST['username'], $_POST['password'])) {
$username = $_POST['username'];
$password = crypt(sha1(md5($_POST['password'])), 'st');
if (empty($username) || empty($password)) {
$error = "Todos os campos têm de ser preenchidos!";
}
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 = "Detalhes incorretos!";
}
}
}
?>
<html>
<head>
<title>AdminPT</title>
<meta charset="UTF-8">
<link rel ="stylesheet" href="../assets/style.css"/>
</head>
<body>
<div class="container">
CMS - PT
<br><br>
<?php
if (isset($error)) { ?>
<small style="color:#aa0000"><?php echo $error; ?></small>
<?php } ?>
<br><br>
<form action="index.php" method="post">
<input type ="text" name="username" placeholder="Username"/>
<input type="password" name="password" placeholder="Password"/>
<input type="submit" value="Login"/>
</form>
</div>
</body>
</html>
<?php
}
?>