ok i want to make it to where when you look at there profile it will tell you if they are online or not!
how would i do that ? here is my php script that has some modifications on the profile page but wont show if other users are online! here is the login script where i put the session and the profile page.
login.php
PHP Code:
<?php
// Start Session to enable creating the session variables below when they log in
session_start();
// Force script errors and warnings to show on page in case php.ini file is set to not display them
error_reporting(E_ALL);
ini_set('display_errors', '1');
//-----------------------------------------------------------------------------------------------------------------------------------
// Initialize some vars
$errorMsg = '';
$email = '';
$pass = '';
$remember = '';
if (isset($_POST['email'])) {
// error handling conditional checks go here
if ((!$email) || (!$pass)) {
$errorMsg = '<font color="red">Please fill in both fields</font>';
} else { // Error handling is complete so process the info if no errors
include 'scripts/connect_to_mysql.php'; // Connect to the database
$email = mysql_real_escape_string($email); // After we connect, we secure the string before adding to query
//$pass = mysql_real_escape_string($pass); // After we connect, we secure the string before adding to query
$pass = md5($pass); // Add MD5 Hash to the password variable they supplied after filtering it
// Make the SQL query
$sql = mysql_query("SELECT * FROM myMembers WHERE email='$email' AND password='$pass' AND email_activated='1'");
$login_check = mysql_num_rows($sql);
// If login check number is greater than 0 (meaning they do exist and are activated)
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
// Pleae note: Adam removed all of the session_register() functions cuz they were deprecated and
// he made the scripts to where they operate universally the same on all modern PHP versions(PHP 4.0 thru 5.3+)
// Create session var for their raw id
$id = $row["id"];
$_SESSION['id'] = $id;
// Create the idx session var
$_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id");
// Create session var for their username
$username = $row["username"];
$_SESSION['username'] = $username;
//THIS IS WHERE I EDITED THE SESSION TO SAY IF THERE LOGGED IN OR NOT
$logedin = $row['id'];
$_SESSION['islogedin']=$logedin;
mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id' LIMIT 1");
// THIS WAS JUST A TEST BUT WONT UPDATE UNTILL THEY LOGOUT
mysql_query("UPDATE myMembers SET online='online' WHERE id='$id' LIMIT 1");
} // close while
// Remember Me Section
if($remember == "yes"){
$encryptedID = base64_encode("g4enm2c0c4y3dn3727553$id");
setcookie("idCookie", $encryptedID, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days
setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days
}
// All good they are logged in, send them to homepage then exit script
header("location: home.php?test=$id");
exit();
} else { // Run this code if login_check is equal to 0 meaning they do not exist
$errorMsg = "<h3><font color='red'>Email/Password invalid<br /></font></h3><a href='forgot_pass.php'>Forgot password?</a><div align='right'> <br> Forget to activate you account?</div>";
}
// Start_session, check if user is logged in or not, and connect to the database all in one included file
include_once("scripts/checkuserlog.php");
if (!$_SESSION['idx']) {
$msgToUser = '<br /><br /><font color="#FF0000">Sorry but you must be logged in to view this page!</font><p><br><div align="right"><a href="register.php">Join Here</a></div><form id="signinform" action="login.php" method="post" enctype="multipart/form-data" name="signinform">
<fieldset>
<input type="submit" style="margin: -20px 0 0 287px;" class="button" name="commit" value="Sign In"/>
</fieldset>
</form></p>';
include_once 'msgToUser.php';
exit();
} else if ($logOptions_id != $_SESSION['id']) {
$msgToUser = '<br /><br /><font color="#FF0000">Only site members can do that</font><p><a href="register.php">Join Here</a></p>';
include_once 'msgToUser.php';
exit();
}
// Include the class files for auto making links out of full URLs and for Time Ago date formatting
include_once("wi_class_files/autoMakeLinks.php");
include_once ("wi_class_files/agoTimeFormat.php");
// Create the two new objects before we can use them below in this script
$activeLinkObject = new autoActiveLink;
$myObject = new convertToAgo;
?>
<?php
// ------- INITIALIZE SOME VARIABLES ---------
// they must be initialized in some server environments or else errors will get thrown
$id = "";
$username = "";
$firstname = "";
$lastname = "";
$mainNameLine = "";
$country = "";
$state = "";
$city = "";
$zip = "";
$bio_body = "";
$website = "";
$youtube = "";
$facebook = "";
$twitter = "";
$twitterWidget = "";
$locationInfo = "";
$user_pic = "";
$blabberDisplayList = "";
$interactionBox = "";
$cacheBuster = rand(999999999,9999999999999); // Put on an image URL will help always show new when changed
// ------- END INITIALIZE SOME VARIABLES ---------
// ------- ESTABLISH THE PAGE ID ACCORDING TO CONDITIONS ---------
if (isset($_GET['id'])) {
$id = preg_replace('#[^0-9]#i', '', $_GET['id']); // filter everything but numbers
} else if (isset($_SESSION['idx'])) {
$id = $logOptions_id;
} else {
header("location: index.php");
exit();
}
// ------- END ESTABLISH THE PAGE ID ACCORDING TO CONDITIONS ---------
// ------- FILTER THE ID AND QUERY THE DATABASE --------
$id = preg_replace('#[^0-9]#i', '', $id); // filter everything but numbers on the ID just in case
$sql = mysql_query("SELECT * FROM myMembers WHERE id='$id' LIMIT 1"); // query the member
// ------- FILTER THE ID AND QUERY THE DATABASE --------
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 0) { // evaluate the count
header("location: home.php?msg=user_does_not_exist");
exit();
}
// ------- END MAKE SURE PERSON EXISTS IN DATABASE ---------
// ------- WHILE LOOP FOR GETTING THE MEMBER DATA ---------
while($row = mysql_fetch_array($sql)){
$username = $row["username"];
$firstname = $row["firstname"];
$lastname = $row["lastname"];
$country = $row["country"];
$state = $row["state"];
$city = $row["city"];
$sign_up_date = $row["sign_up_date"];
$sign_up_date = strftime("%b %d, %Y", strtotime($sign_up_date));
$last_log_date = $row["last_log_date"];
$last_log_date = strftime("%b %d, %Y", strtotime($last_log_date));
$bio_body = $row["bio_body"];
$bio_body = str_replace("'", "'", $bio_body);
$bio_body = stripslashes($bio_body);
$website = $row["website"];
$youtube = $row["youtube"];
$facebook = $row["facebook"];
$twitter = $row["twitter"];
$friend_array = $row["friend_array"];
/////// Mechanism to Display Pic. See if they have uploaded a pic or not //////////////////////////
$check_pic = "members/$id/image01.jpg";
$default_pic = "members/0/image01.jpg";
if (file_exists($check_pic)) {
$user_pic = "<img src=\"$check_pic?$cacheBuster\" width=\"218px\" />";
} else {
$user_pic = "<img src=\"$default_pic\" width=\"218px\" />";
}
/////// Mechanism to Display Real Name Next to Username - real name(username) //////////////////////////
if ($firstname != "") {
$mainNameLine = "$firstname$lastname ($username)";
$username = $firstname;
} else {
$mainNameLine = $username;
}
/////// Mechanism to Display Youtube channel link or not //////////////////////////
if ($youtube == "") {
$youtube = "";
} else {
$youtube = '<br /><br /><img src="images/youtubeIcon.jpg" width="18" height="12" alt="Youtube Channel for ' . $username . '" /> <strong>YouTube Channel:</strong><br /><a href="http://www.youtube.com/user/' . $youtube . '" target="_blank">youtube.com/' . $youtube . '</a>';
}
/////// Mechanism to Display Facebook Profile link or not //////////////////////////
if ($facebook == "") {
$facebook = "";
} else {
$facebook = '<br /><br /><img src="images/facebookIcon.jpg" width="18" height="12" alt="Facebook Profile for ' . $username . '" /> <strong>Facebook Profile:</strong><br /><a href="http://www.facebook.com/profile.php?id=' . $facebook . '" target="_blank">profile.php?id=' . $facebook . '</a>';
}
/////// Mechanism to Display Twitter Tweet Widget or not //////////////////////////
if ($twitter == "") {
$twitterWidget = "";
} else {
$twitterWidget = "<script src=\"http://widgets.twimg.com/j/2/widget.js\"></script>
<script>
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 5,
interval: 6000,
width: 218,
height: 160,
theme: {
shell: {
background: '#BDF',
color: '#000000'
},
tweets: {
background: '#ffffff',
color: '#000000',
links: '#0066FF',
}
},
features: {
scrollbar: true,
loop: false,
live: false,
hashtags: true,
timestamp: true,
avatars: false,
behavior: 'all'
}
}).render().setUser('$twitter').start();
</script>";
}
/////// Mechanism to Display Website URL or not //////////////////////////
if ($website == "") {
$website = "";
} else {
$website = '<br /><br /><img src="images/websiteIcon.jpg" width="18" height="12" alt="Website URL for ' . $username . '" /> <strong>Website:</strong><br /><a href="http://' . $website . '" target="_blank">' . $website . '</a>';
}
/////// Mechanism to Display About me text or not //////////////////////////
if ($bio_body == "") {
$bio_body = "";
} else {
$bio_body = '<div class="infoBody">' . $bio_body . '</div>';
}
/////// Mechanism to Display Location Info or not //////////////////////////
if ($country == "" && $state == "" && $city == "") {
$locationInfo = "";
} else {
$locationInfo = "$city · $state<br />$country ".'<a href="#" onclick="return false" onmousedown="javascript:toggleViewMap(\'google_map\');">view map</a>';
}
} // close while loop
// ------- END WHILE LOOP FOR GETTING THE MEMBER DATA ---------
// ------- POST NEW BLAB TO DATABASE ---------
$blab_outout_msg = "";
if (isset($_POST['blab_field']) && $_POST['blab_field'] != "" && $_POST['blab_field'] != " "){
$blabWipit = $_POST['blabWipit'];
$sessWipit = base64_decode($_SESSION['wipit']);
if (!isset($_SESSION['wipit'])) {
} else if ($blabWipit == $sessWipit) {
// Delete any blabs over 50 for this member
$sqlDeleteBlabs = mysql_query("SELECT * FROM blabbing WHERE mem_id='$id' ORDER BY blab_date DESC LIMIT 50");
$bi = 1;
while ($row = mysql_fetch_array($sqlDeleteBlabs)) {
$blad_id = $row["id"];
if ($bi > 20) {
$deleteBlabs = mysql_query("DELETE FROM blabbing WHERE id='$blad_id'");
}
$bi++;
}
// End Delete any blabs over 20 for this member
$blab_field = $_POST['blab_field'];
$blab_field = stripslashes($blab_field);
$blab_field = strip_tags($blab_field);
$blab_field = mysql_real_escape_string($blab_field);
$blab_field = str_replace("'", "'", $blab_field);
$sql = mysql_query("INSERT INTO blabbing (mem_id, the_blab, blab_date) VALUES('$id','$blab_field', now())") or die (mysql_error());
$blab_outout_msg = "";
}
}
// ------- END POST NEW BLAB TO DATABASE ---------
// ------- MEMBER BLABS OUTPUT CONSTRUCTION ---------
/////// Mechanism to Display Pic
if (file_exists($check_pic)) {
$blab_pic = '<div style="overflow:hidden; height:40px;"><a href="profile.php?id=' . $id . '"><img src="' . $check_pic . '" width="40px" border="0" /></a></div>';
} else {
$blab_pic = '<div style="overflow:hidden; height:40px;"><a href="profile.php?id=' . $id . '"><img src="' . $default_pic . '" width="40px" border="0" /></a></div>';
}
/////// END Mechanism to Display Pic
$sql_blabs = mysql_query("SELECT id, mem_id, the_blab, blab_date FROM blabbing WHERE mem_id='$id' ORDER BY blab_date DESC LIMIT 20");
}
// ------- END MEMBER BLABS OUTPUT CONSTRUCTION ---------
// ------- ESTABLISH THE PROFILE INTERACTION TOKEN ---------
$thisRandNum = rand(9999999999999,999999999999999999);
$_SESSION['wipit'] = base64_encode($thisRandNum); // Will always overwrite itself each time this script runs
// ------- END ESTABLISH THE PROFILE INTERACTION TOKEN ---------
// ------- EVALUATE WHAT CONTENT TO PLACE IN THE MEMBER INTERACTION BOX -------------------
// initialize some output variables
$friendLink = "";
$the_blab_form = "";
if (isset($_SESSION['idx']) && $logOptions_id != $id) { // If SESSION idx is set, AND it does not equal the profile owner's ID
// SQL Query the friend array for the logged in viewer of this profile if not the owner
$sqlArray = mysql_query("SELECT friend_array FROM myMembers WHERE id='" . $logOptions_id ."' LIMIT 1");
while($row=mysql_fetch_array($sqlArray)) { $iFriend_array = $row["friend_array"]; }
$iFriend_array = explode(",", $iFriend_array);
if (in_array($id, $iFriend_array)) {
$friendLink = '<a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'remove_friend\');">Remove Friend</a>';
} else {
$friendLink = '<a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'add_friend\');">Add as Friend</a>';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$interactionBox = '<br /><br /><div class="interactionLinksDiv">
' . $friendLink . '
<a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'private_message\');">Private Message</a>
</div><br />';
$the_blab_form = '<div style="background-color:#BDF; border:#999 1px solid; padding:8px;">
<textarea name="blab_field" rows="3" style="width:99%;"></textarea>
<strong>Write on ' . $username . '\'s Board (coming soon)</strong>
</div>';
} else if (isset($_SESSION['idx']) && $logOptions_id == $id) { // If SESSION idx is set, AND it does equal the profile owner's ID
$interactionBox = '<br /><br /><div class="interactionLinksDiv">
<a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'friend_requests\');">Friend Requests</a>
</div><br />';
$the_blab_form = ' ' . $blab_outout_msg . '
<div style="background-color:#BDF; border:#999 1px solid; padding:8px;">
<form action="profile.php" method="post" enctype="multipart/form-data" name="blab_from">
<textarea name="blab_field" rows="3" style="width:99%;"></textarea>
<input name="blabWipit" type="hidden" value="' . $thisRandNum . '" />
<strong>Blab away ' . $username . '</strong> (220 char max) <input name="submit" type="submit" value="Blab" />
<div align="right">
</form></div>';
} else { // If no SESSION id is set, which means we have a person who is not logged in
$interactionBox = '<div style="border:#CCC 1px solid; padding:5px; background-color:#E4E4E4; color:#999; font-size:11px;">
<a href="register.php">Sign Up</a> or <a href="login.php">Log In</a> to interact with ' . $username . '
</div>';
$the_blab_form = '<div style="background-color:#BDF; border:#999 1px solid; padding:8px;">
<textarea name="blab_field" rows="3" style="width:99%;"></textarea>
<a href="register.php">Sign Up</a> or <a href="login.php">Log In</a> to write on ' . $username . '\'s Board
</div>';
}
// ------- END EVALUATE WHAT CONTENT TO PLACE IN THE MEMBER INTERACTION BOX -------------------
// ------- POPULATE FRIEND DISPLAY LISTS IF THEY HAVE AT LEAST ONE FRIEND -------------------
$friendList = "";
$friendPopBoxList = "";
if ($friend_array != "") {
// ASSEMBLE FRIEND LIST AND LINKS TO VIEW UP TO 6 ON PROFILE
$friendArray = explode(",", $friend_array);
$friendCount = count($friendArray);
$friendArray6 = array_slice($friendArray, 0, 6);
$friendList .= '<div class="infoHeader">' . $username . '\'s Friends (<a href="#" onclick="return false" onmousedown="javascript:toggleViewAllFriends(\'view_all_friends\');">' . $friendCount . '</a>)</div>';
$i = 0; // create a varible that will tell us how many items we looped over
$friendList .= '<div class="infoBody" style="border-bottom:#666 1px solid;"><table id="friendTable" align="center" cellspacing="4"></tr>';
foreach ($friendArray6 as $key => $value) {
$i++; // increment $i by one each loop pass
$check_pic = 'members/' . $value . '/image01.jpg';
if (file_exists($check_pic)) {
$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="' . $check_pic . '" width="54px" border="1"/></a>';
} else {
$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="members/0/image01.jpg" width="54px" border="1"/></a> ';
}
$sqlName = mysql_query("SELECT username, firstname FROM myMembers WHERE id='$value' LIMIT 1") or die ("Sorry we had a mysql error!");
while ($row = mysql_fetch_array($sqlName)) { $friendUserName = substr($row["username"],0,12); $friendFirstName = substr($row["firstname"],0,12);}
if (!$friendUserName) {$friendUserName = $friendFirstName;} // If username is blank use the firstname... programming changes in v1.32 call for this
if ($i % 6 == 4){
$friendList .= '<tr><td><div style="width:56px; height:68px; overflow:hidden;" title="' . $friendUserName . '">
<a href="profile.php?id=' . $value . '">' . $friendUserName . '</a><br />' . $frnd_pic . '
</div></td>';
} else {
$friendList .= '<td><div style="width:56px; height:68px; overflow:hidden;" title="' . $friendUserName . '">
<a href="profile.php?id=' . $value . '">' . $friendUserName . '</a><br />' . $frnd_pic . '
</div></td>';
}
}
$friendList .= '</tr></table>
<div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleViewAllFriends(\'view_all_friends\');">view all</a></div>
</div>';
// END ASSEMBLE FRIEND LIST... TO VIEW UP TO 6 ON PROFILE
// ASSEMBLE FRIEND LIST AND LINKS TO VIEW ALL(50 for now until we paginate the array)
$i = 0;
$friendArray50 = array_slice($friendArray, 0, 50);
$friendPopBoxList = '<table id="friendPopBoxTable" width="100%" align="center" cellpadding="6" cellspacing="0">';
foreach ($friendArray50 as $key => $value) {
$i++; // increment $i by one each loop pass
$check_pic = 'members/' . $value . '/image01.jpg';
if (file_exists($check_pic)) {
$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="' . $check_pic . '" width="54px" border="1"/></a>';
} else {
$frnd_pic = '<a href="profile.php?id=' . $value . '"><img src="members/0/image01.jpg" width="54px" border="1"/></a> ';
}
$sqlName = mysql_query("SELECT username, firstname, country, state, city FROM myMembers WHERE id='$value' LIMIT 1") or die ("Sorry we had a mysql error!");
while ($row = mysql_fetch_array($sqlName)) { $funame = $row["username"]; $ffname = $row["firstname"]; $fcountry = $row["country"]; $fstate = $row["state"]; $fcity = $row["city"]; }
if (!$funame) {$funame = $ffname;} // If username is blank use the firstname... programming changes in v1.32 call for this
if ($i % 2) {
$friendPopBoxList .= '<tr bgcolor="#F4F4F4"><td width="14%" valign="top">
<div style="width:56px; height:56px; overflow:hidden;" title="' . $funame . '">' . $frnd_pic . '</div></td>
<td width="86%" valign="top"><a href="profile.php?id=' . $value . '">' . $funame . '</a><br /><font size="-2"><em>' . $fcity . '<br />' . $fstate . '<br />' . $fcountry . '</em></font></td>
</tr>';
} else {
$friendPopBoxList .= '<tr bgcolor="#E0E0E0"><td width="14%" valign="top">
<div style="width:56px; height:56px; overflow:hidden;" title="' . $funame . '">' . $frnd_pic . '</div></td>
<td width="86%" valign="top"><a href="profile.php?id=' . $value . '">' . $funame . '</a><br /><font size="-2"><em>' . $fcity . '<br />' . $fstate . '<br />' . $fcountry . '</em></font></td>
</tr>';
}
}
$friendPopBoxList .= '</table>';
// END ASSEMBLE FRIEND LIST AND LINKS TO VIEW ALL(50 for now until we paginate the array)
}
// ------- END POPULATE FRIEND DISPLAY LISTS IF THEY HAVE AT LEAST ONE FRIEND -------------------
//HERE IS WHERE I STARTED , BUT dONT KNOW WHAT TO DO !
if (isset($_SESSION['islogedin']) && $logOptions_id != $id) {
$isonline = "<font color='green'>online</font>";
}
else{
$isonline = "<font color='red'>offline</font>";
}
<!-- START DIV that serves as an interaction status and results container that only appears when we instruct it to -->
<div id="interactionResults" style="font-size:15px; padding:10px;"></div>
<!-- END DIV that serves as an interaction status and results container that only appears when we instruct it to -->
<!-- START DIV that contains the Private Message form -->
<div class="interactContainers" id="private_message">
<form action="javascript:sendPM();" name="pmForm" id="pmForm" method="post">
<font size="+1">Sending Private Message to <strong><em><?php echo "$username"; ?></em></strong></font><br /><br />
Subject:
<input name="pmSubject" id="pmSubject" type="text" maxlength="64" style="width:98%;" />
Message:
<textarea name="pmTextArea" id="pmTextArea" rows="8" style="width:98%;"></textarea>
<input name="pm_sender_id" id="pm_sender_id" type="hidden" value="<?php echo $_SESSION['id']; ?>" />
<input name="pm_sender_name" id="pm_sender_name" type="hidden" value="<?php echo $_SESSION['username']; ?>" />
<input name="pm_rec_id" id="pm_rec_id" type="hidden" value="<?php echo $id; ?>" />
<input name="pm_rec_name" id="pm_rec_name" type="hidden" value="<?php echo $username; ?>" />
<input name="pmWipit" id="pmWipit" type="hidden" value="<?php echo $thisRandNum; ?>" />
<span id="PMStatus" style="color:#F00;"></span>
<br /><input name="pmSubmit" type="submit" value="Submit" /> or <a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers('private_message');">Close</a>
<span id="pmFormProcessGif" style="display:none;"><img src="images/loading.gif" width="28" height="10" alt="Loading" /></span></form>
</div>
<!-- END DIV that contains the Private Message form -->
<div class="interactContainers" id="friend_requests" style="background-color:#FFF; height:240px; overflow:auto;">
<div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers('friend_requests');">close window</a> </div>
<h3>The following people are requesting you as a friend</h3>
<?php
$sql = "SELECT * FROM friends_requests WHERE mem2='$id' ORDER BY id ASC LIMIT 50";
$query = mysql_query($sql) or die ("Sorry we had a mysql error!");
$num_rows = mysql_num_rows($query);
if ($num_rows < 1) {
echo 'You have no Friend Requests at this time.';
} else {
while ($row = mysql_fetch_array($query)) {
$requestID = $row["id"];
$mem1 = $row["mem1"];
$sqlName = mysql_query("SELECT username FROM myMembers WHERE id='$mem1' LIMIT 1") or die ("Sorry we had a mysql error!");
while ($row = mysql_fetch_array($sqlName)) { $requesterUserName = $row["username"]; }
/////// Mechanism to Display Pic. See if they have uploaded a pic or not //////////////////////////
$check_pic = 'members/' . $mem1 . '/image01.jpg';
if (file_exists($check_pic)) {
$lil_pic = '<a href="profile.php?id=' . $mem1 . '"><img src="' . $check_pic . '" width="50px" border="0"/></a>';
} else {
$lil_pic = '<a href="profile.php?id=' . $mem1 . '"><img src="members/0/image01.jpg" width="50px" border="0"/></a>';
}
echo '<hr />
<table width="100%" cellpadding="5"><tr><td width="17%" align="left"><div style="overflow:hidden; height:50px;"> ' . $lil_pic . '</div></td>
<td width="83%"><a href="profile.php?id=' . $mem1 . '">' . $requesterUserName . '</a> wants to be your Friend!<br /><br />
<span id="req' . $requestID . '">
<a href="#" onclick="return false" onmousedown="javascript:acceptFriendRequest(' . $requestID . ');" >Accept</a>
OR
<a href="#" onclick="return false" onmousedown="javascript:denyFriendRequest(' . $requestID . ');" >Deny</a>
</span></td>
</tr>
</table>';
}
}
?>
</div>
I don't have time to go through these millions of lines of code, but in general, every time a user makes a request to a page, and is logged in, you update their database row, which should contain a field called 'last_activity' or similar, and insert the current time.
Then on the profile, you check if ($lastActivity >= time() - (60 * 20)). If that's true, the user has been active in the past 20 minutes.