He means, where is $_SESSION['login'] getting set? You’ll need to make sure it’s being set correctly in the first place, e.g., by sticking a var_dump() right after session_start():
<?php
session_start();
var_sump($_SESSION);
if (...) {
header(...);
}
It’s just a debugging tip. If you’re trying to figure out why you’re being redirected, the first thing you have to do is figure out why that if() condition is evaluating to true. A quick way to do that is to dump out the contents of $_SESSION to make sure it contains what you think it contains. Since it doesn’t, the most likely spot that it’s failing is where you’re logging the user in.
What does your login code look like, i.e., the code that your login form submits to?
tombempty: you might be missing some key concepts here…
#1 HTTP requests don’t share data between them, so, a variable set in one, will not be set in another.
That means, you need a session_start(); on all your pages, before any output (including headers).
#2 After your session_start();, you can populate your $_SESSION with variables.
#3 Also, after your session_start();, you can retrieve variables from your $_SESSION.
#4 Sessions are stored on the server (just session ID on the client PC), so users can’t change it. But they can change the session ID and take over the session of some other user.
#5 There is no need to pass the user and the password, you already validated the user on login, so just pass the userId.
Here is an example:
page1.php
session_start();
# Validate the user name and pass, and get whatever user logged in
$_SESSION['userId'] = 123;
page2.php
session_start();
# make sure the user has a session here
if (!iisset($_SESSION['userId'])) {
header('Location: /');
exit;
}
# rest of your page
Your login script is setting different session variables than those your checking for…
Your checking for ‘login’ and your setting ‘myusername’ and ‘mypassword’…