Jump to content

user is online


Glenskie

Recommended Posts

ok well i have this is online script that starts at the login page where it sets  a session. well it echos that that person is online even if they are not, i will have all of the code only for the online script so it will be in peaces.

ok so here is the login page where the session is started

login.php

 

<?php
//ok so if they submit the page and its all right and they login , here is the session that is set for the person, again its just the piece of the script .
$_SESSION['logedin'] = $_POST['email'];
                    mysql_query("UPDATE myMembers SET last_activity=now() WHERE id='$id'");
?>

now here is where i call on the session and see if there online , the profile.php is set up to where it sees if it is your profile or not so $logoptions_id is the id that they are logged in as.

profile.php

<?php
// this is on top of the page , where the session is called and if they are logged in it updates the database where there id is. 
if( isset($_SESSION['logedin']) ) {
mysql_query("UPDATE myMembers SET last_activity=now() WHERE id='$logOptions_id'");// there is where $logOptions_id comes in.
}
// now this is further down the page(script) where we see if they are logged in or not.
$age= 60; //set a variable called age, assign an integer of 60 to it.
if( isset($_SESSION['logedin']) ) { 
$q = 'SELECT id=`$id`, DATE_FORMAT(`last_activity`,"%a, %b %e %T") as `last_activity`,UNIX_TIMESTAMP(`last_activity`) as `last_activity_stamp`FROM `mymembers`WHERE `$id` <> \''.($_SESSION['logedin']).'\''; 
$isonlinecheck = mysql_query($q);
$row = mysql_fetch_assoc($isonlinecheck); 
if (($row['last_activity_stamp'] + $age)< time()){
	$isonline =  "is <font color='green'>online!</font>";} 
else {
$isonline = "is<font color='red'> offline!</font>";
}

}
?>

i wana thank all who helps! your all greatly appreciated

Link to comment
https://forums.phpfreaks.com/topic/247988-user-is-online/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.