SOLVED: There was a stupid mistake which caused this problem. In header.php i wrote $_SESSION[“header”] (which doesnt even exist) instead of $_SESSION[“logged”]. Thanks to everyone for your help.
Login.php does not want to redirect after i enter correct login information.
The page just refreshes and clears the input fields.
(Also the session is created in /tmp folder )
Does anyone have any ideas? :S
Thanks in advance! 🙂
login.php:
<?php
$message = NULL;
if (isset($_POST["enter"])) {
include 'cred.php';
$newUser = $_POST["user"];
$newPass = md5($_POST["pass"]);
if ($newUser==$user AND $newPass==$pass) {
session_start();
$_SESSION["logged"]=1;
$_SESSION["user"]=$newUser;
header('Location: index.php');
exit;
} else {
$message = 'failure';
}
}
?>
<head>
<style type="text/css">
body {
margin-top:120px;
}
</style>
</head>
<body>
<center>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
Uporabnik:<br /> <input type="text" name="user" /><br /><br />
Geslo:<br /> <input type="password" name="pass" /><br /><br />
<input type="submit" value="submit" name="enter"/><br /><br />
<?php if($message!=NULL) {echo $message;} ?>
</form>
</center>
</body>
cred.php:
<?php
$user = 'janeznovak';
$pass= md5('greek123');
?>
EDIT : Added the header.php file, which is part of every (index.php, second.php, third.php) page. Maybe the problem lies here:
<?php
session_start();
if(!isset($_SESSION["header"])OR $_SESSION["header"]!=1){
header('Location: login.php');
exit;
} else {
$nuser = $_SESSION["user"];
}
?>
<head>
</head>
<body>
<div>
<a href="index.php">Prva</a> |
<a href="second.php">Druga</a> |
<a href="third.php">Tretja</a> |
<a href="logout.php">Logout</a> |
Prijavljeni ste kot <?php echo $nuser; ?>
</div>
add one more session variable on your login.php
hope now it will work.