2
I just made a website that enables CMS so that our client can login and modify the content to his liking. On the localhost and on a test server that we have works very well, but on the final target server I can’t leave the login page after filling in the correct details.
There are 2 possible outcomes Submit:
- stay on the form page
- and if it’s all right he does the
redirect
to the menu.
But it doesn’t do the redirect
and none of the validation messages appear either. I went to the browser console and the only difference I saw between the Servers is in the response header where this is connection: close
and in others (where it works correctly) is connection: Keep-Alive
. Is this?
I’ve done a lot of research and I can’t find any clear answer to help me solve this problem.
I have even tried to implement header("Connection: Keep-Alive");
in the code but the problem remains, although in the response header it is now connection: Keep-Alive, close
. I also used the var_dump
on localhost appears array(1) { ["logged_in"]=> bool(true) }
. On the final server appears array(0) { }
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
}
?>
Have you tried using the full path in "window.Location"? Although in your case I would use PHP itself, with `header( 'Location: /index.php' ) - However note that the correct in the Location header is to use the full path as well. Nothing to do with the question, but you sticking 3 hashes into each other in the password is only weakening the protection.
– Bacco
Thanks, already redirected with php I also used now var_dump in localhost appears "array(1) { ["logged_in"]=> bool(true) }" in the final server appears "array(0) { } ", ie Session is not being started, but I do not understand why. As for the hashs I just copied a method from youtube that sounded good, but thanks for the advice
– Miguel
Whenever you have a moment, take a peek at this question to learn more about passwords and hashes: http://answall.com/questions/2402/comort-hash-de-passwords-safe
– Bacco
Thank you very much yes I will see already recorded in bookmarks
– Miguel
Have you tried to see if the Phps version is the same? Take a peek at the server error log, there might be some hints there.
– Bacco
Server error log? How do I see it? Excuse my ignorance
– Miguel
I have been investigating and yet sent a cookie with the id Session... I do not understand pk does not redirect, although the result of the Var_dump is "array(0) { }"
– Miguel
Is output_buffering enabled in php.ini? (http://www.php.net/manual/en/outcontrol.configuration.php)
– vmartins