[RESOLVED] Redirect after login
Hi all,
I've been using PHP for about 3 days and I absolutely love it so far. Here's my first question. User tries to access a page and they are not logged in. They are redirected to the login page. After they successfully log in, they are directed back to the page they came from.
Here is and example of how I get to the login page.
PHP Code:
if (!isset($_SESSION['loggedin_username'])) {
header('Location: login.php?url=' . urlencode($_SERVER['SCRIPT_NAME']));
}
Here is and example of what the url looks like in the browser after reaching the login page from above.
Code:
http://127.0.0.1/www/ff/login.php?url=%2Fwww%2Fff%2Feditpost.php
Here is the block that is trying to redirect after a successfull login. $count returns 1 if the user is in the DB.
PHP Code:
if ($count == 1) {
// The user exists. Register them.
$_SESSION['loggedin_id'] = $userid;
$_SESSION['loggedin_username'] = $username;
// Redirect the user to the page that they came from.
if (isset($_GET['url'])) {
$url = $_GET['url'];
} else {
$url = 'index.php';
}
header("Location: $url");
}
However, I always get directed back to index.php. But if I echo the $_GET['id'] variable it will show a valid url such as /www/ff/editpost.php.
What stupid mistake am I making? Thanks.
Re: [RESOLVED] Redirect after login
Anytime. I love php :) If you get stumped just drop me a line.