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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.