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.
Here is and example of what the url looks like in the browser after reaching the login page from above.PHP Code:if (!isset($_SESSION['loggedin_username'])) {
header('Location: login.php?url=' . urlencode($_SERVER['SCRIPT_NAME']));
}
Here is the block that is trying to redirect after a successfull login. $count returns 1 if the user is in the DB.Code:http://127.0.0.1/www/ff/login.php?url=%2Fwww%2Fff%2Feditpost.php
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.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");
}
What stupid mistake am I making? Thanks.




Reply With Quote