Hi folks,
I'm using this simple user log in script from a tutorial on the subject, I use the term tutorial loosely as it was one of those that gives a little vague talk on the subject then just a bunch of code you can use as you please and figure it out for yourself if you want to bash it about for any reason, so I'm not overly knowledgable on 'sessions' yet.
// Check for login status
session_start();
$user_check = $_SESSION['login_user'];
$ses_query = mysql_query("SELECT member_name, member_ID FROM members WHERE member_name = '$user_check' ");
$row = mysql_fetch_array($ses_query);
$member_name = $row['member_name'];
$member_ID = $row['member_ID'];
if(!isset($member_name))
{
header("Location: http://www.website.com/login.php");
}
-- Login.php
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST"){
// username and password sent from Form
$myusername = addslashes($_POST['username']);
$mypassword = addslashes($_POST['password']);
$query = "SELECT member_ID FROM members WHERE member_name='$myusername' and member_pw='$mypassword'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$active = $row['active'];
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: http://www.website.com/index.php");
} // end if
else{
$error = "Your Login Name or Password is invalid";
} // end else
} // end if
My first question about this code is the line '$active = $row['active'];' - I'm not sure what ['active'] is as it doesn't occur in the database nor anywhere else in the script so in theory it's not infact anything at all, or am I missing something here?
My main wish tho is to create a basic list of names for everyone currently logged in to the site. Is there a relatively simple method on the basis of the above script. My theory so far is I'll need to add some sort of 'online' field to the members table which can be updated depending on their status, then just grab the names from that table where they're makes as logged in. The trouble is tho that a lot of folk don't actively log out, so if the browser is closed I can't modify their status to 'offline'.
Any thoughts or pointers in the right direction would be great.
I've been recomended to start using firefox and the web developer toolkit add on I think it's called, apparently useful for seeing what's going on with sessions, cookies and suchlike...