Beginner here wondering what I did wrong. After going to profile.php and getting redirected to login.php, and then logging in, user is always redirected to BASE URL. I want the user to be redirected to profile.php.
profile.php
if (!isset($_SESSION['id'])) {
$_SESSION['redirect'] = $_SERVER['REQUEST_URI'];
$url = BASE_URL . 'login.php';
ob_end_clean();
header("Location: $url");
exit();
} else {
echo 'Logged in'
}
login.php
$q = "SELECT * FROM users WHERE (username='$username' AND password=SHA1('$password'))";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br>MySQL Error: " . mysqli_error($dbc));
if (@mysqli_num_rows($r) == 1) {
$_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC);
mysqli_free_result($r);
mysqli_close($dbc);
$url = BASE_URL . $_SESSION['redirect'];
ob_end_clean();
header("Location: $url");
exit();
} else {
echo 'Message';
}
Also tried using $_GET variable but the same issue occurs. Very confused with what is wrong.