When the user logs in, the first page of retrieving data from the session is fine. When I go to another page, the session is blank.
I have found out that the session id changes, when the user logs in and is getting the first user page which is card.php. When going to for instance subscription.php, the session id is different for whatever reason.
I have tried to list useful code underneath:
log-user-in.php:
<?
session_start();
include('includingThis.php');
unset($_SESSION["emaillogin"]);
// Sørg for at e-mailen er undercased
$email = addslashes($_POST[email]);
$password = addslashes($_POST[pass]);
if ($email == "" || $password == "") {
header("Location: login.php?e=3");
exit;
die();
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: login.php?e=4");
exit;
die();
}
$email = strtolower($email);
// TJEK OM BRUGEREN FINDES
if ($stmt = $con->prepare("SELECT email, pass, uid, profilepic, paid FROM stnd_users WHERE email=?")) {
/* bind parameters for markers */
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($em, $pa, $u, $pp, $pai);
// Loop through each row in the result set
while ($stmt->fetch()) {
$gottenEmail = $em;
$gottenPass = $pa;
$uid = $u;
$profile_pic = $pp;
$paid = $pai;
}
$stmt->close();
}
if ($gottenEmail == "" || $gottenPass == "") {
header("Location: login.php?e=5");
exit;
die();
}
if (password_verify($password, $gottenPass)) {
// BRUGER LOGGES IND
// NÅR BRUGEREN FINDES, OG KODEN ER KORREKT
if ($uid != "") {
$_SESSION["user"] = $uid;
if ($paid == "true") {
// Bruger har betalt
if ($profile_pic == "true") {
header("Location: user/card.php");
exit;
} else {
header("Location: user/profilepic.php");
exit;
}
} else {
// Bruger har IKKE betalt
header("Location: user/inactive.php");
exit;
}
} else {
//DER ER SKET EN FEJL, INTET UID
header("Location: login.php?e=6");
exit;
die();
}
} else {
//Oplysningerne er ikke korrekte, har du tastet rigtigt?
// (Kode ikke korrekt)
header("Location: login.php?e=5");
exit;
die();
}
?>