Welcome to WebmasterWorld Guest from 54.167.174.11

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Users Logged In list

   
12:23 pm on Jan 29, 2012 (gmt 0)

5+ Year Member



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...
1:01 pm on Jan 29, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



it looks like $row['active'] is referring to a field in the database. it's probably there for the same reason that your new 'online' field would be there. you've got the right idea, you just need to add that new column.

if it was me, i would change the field to whatever the current time is at the same point in the script as session_register("myusername");

you can update the time again everytime they make a post, or interact with something.

to see how many people are online, just check for the ones that are within 20 minutes (or whatever) of the current time. then it wont matter if they dont log out.

but if they do actively log out, then change the time to something in the past, so they dont appear on the "within 20 minutes" list
2:08 pm on Jan 29, 2012 (gmt 0)

5+ Year Member



Cheers!

Well I'm glad I'm not just being dim somehow! :) ['active'] doesn't exist as a field in the tutorial db table they started with so I guess the writer was thinking about smething more in-depth or just forgot to crop that out of some more advanced script they chose to use for the tutorial. Still, it's put me on the right lines.

Yea I read about a time check being the easiest way generally so Ill see how I go, thanks again for the vote of confidence :)
10:09 pm on Feb 1, 2012 (gmt 0)

5+ Year Member



Out of curiosity, any idea just what the breaking point is for a typical sql database :D

I mean if you had a snippet of code on every page that updated a time field in a log table for the current user, how many users would you need online at the same time browsing lots of pages and changing the timestamp on all their respective rows every couple of seconds?

How many queries do you have to send before it starts feeling the pressure.
10:32 pm on Feb 1, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



That is a duplicate question that you posted in [webmasterworld.com...]
4:56 pm on Feb 2, 2012 (gmt 0)

5+ Year Member



Oops, sorry! I decided it was better off in 'databases' but forgot to remove it here