I have a page in a main window where you click on a link that opens a small login window. There you fill in name and password, which are compared to the database and if everything's correct the login window closes and a new page opens i the main window.
Now, I want sessions for this, so that I on the new page can check whether the user has actually logged in and not just stumbled upon the "right" page.
Though PHP doesn't feel like doing as I want it to.
The first time I log in, it seems as the sessions variable isn't registered and I get a "wrong login" on the new page. But if I go back and try again, it works perfectly fine. When I close the browser and start it up again the same thing happens again.
In the login window I've got this code:
if (isset($_POST['login'])) {
mysql connections are made here
if (!($row = mysql_fetch_array($result))) {
usch();
} else {
session_start();
$_SESSION['session_id'] = $row['id'];
duktigt();
}
} else {
form is showed.
}
duktigt() starts a javascript that closes the login window and opens the page main.php in the main window (the window from where you opened the login window).
In main.php it says:
session_start();
if (!isset($_SESSION['session_id'])) {
echo "you'll have to try harder than that";
} else {
all the fun stuff
}
Can't really see what's causing this..