I was making a website for someone with a basic login system. I made it, and it was working fine for months, until now. User logs in, user/pass checked with the database, session variable set to "loggedin" or whatever, and then headers the user to the "private" page.
Now, for some reason, the pages just aren't saving the session variables so when the private page checks if the user is logged in (calls this function):
And it immediately links me back to the main page.Code:function logincheck() { if (!isset($_SESSION['userloggedin'])) { header("Location: non private index"); } }
Having removed the check to see what was going on, i am confronted with a myriad errors claiming that loops are incorrectly done, divisions by zero all over the shop, etc.
From a little fiddling, it is apparent that the session data isn't being carried. All the pages have the usual
snippet, and as i said, it was working great up until today.Code:<?php session_start();
Any ideas about what could be up? I was wondering if it's my hosting company's fault - QiQ, or whether it's a database problem (unlikely i expect and i can't see how it would screw up sessions). I've checked phpinfo() and sessions are enabled - as they should be.
The weirdest thing is that i can try with a really simple test case like:
And it'll output "hi" like it should.Code:<?php session_start(); $_SESSION['test'] = "hi"; header(location:"2.php"); ?> 2.php <?php session_start(); echo $_SESSION['test']; ?>
Any ideas on what could be causing the error?
EDIT:
This is the login bit that headers to the private page:
Obviously the login page also has session_start(); at the top..Code:elseif ($num == 1) { $sql = "SELECT * FROM stats WHERE username = '$username'"; $result = $db->query($sql); $row = $db->fetcharray($result); $_SESSION['userloggedin'] = 1; $_SESSION['userid'] = $row['id']; header("Location: Private Site");


LinkBack URL
About LinkBacks
Reply With Quote

