kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi Your query above gives you what you need to let you know if someone is logged in. If you remove the WHERE clause you would get a list of who is logged in and who is not logged in. If you update last_access every time they do anything like this (as posted above) then the last_access will always be up to date:- $sSqlSec = "Update ".tbl_author." Set last_access = NOW() where id='$userid' and TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15"; $resultSec = mysql_query($sSqlSec,$conn) or die(mysql_error()); if (mysql_affected_rows() < 1) { header('Location:../Logout.php'); // Or do something else should they not have done anything in the last 15 mins exit(); } Anyone who has not logged off but just sat there looking at the same screen for 2 hours will be treated by the system as being logged off after 15 mins. If you want to cope with people manually logging off then just put some code in the log out script to set the last_access datetime to something in the past. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-842180 Share on other sites More sharing options...
deepson2 Posted May 26, 2009 Author Share Posted May 26, 2009 good morning keith, you know i am sort of near to finish this. ll tell you, 1) login.php $result12 = $op->runsql("UPDATE ".tbl_author." SET last_access = NOW(),status = '1' WHERE username='$username' AND password='".md5($passwd)."'"); 2) profile.php // where actually i am showing user's profile $res = $op->runsql("SELECT * FROM ".tbl_author." a WHERE a.id = '$blogdata->author' "); if(mysql_num_rows($res)>0){ while($row1 = $op->select($res)){ if($row1['status'] ==1){ echo "online"; }else{ echo "offline"; } }} 3)logout.php $update = $op->runsql("UPDATE ".tbl_author." SET status = '0' WHERE id = '$userid'"); well why i switched to this again because using this out of 3 problems, 2 are going to be solved. HOW- 1) user dont have to log in again and again till he/ she himself/herself dont want to do log out 2)before 15 minutes,if user want to do log out then he/she can simply do log out and leave. the only remaining condition is what if user closes the browser as it is without logged out. so for that i can apply this method TIMESTAMPDIFF( MINUTE , last_access , CURRENT_TIMESTAMP ) <=120 //after 2 hours if this condition satisfies than just change the status of that particular user to 0. but got stucked with where to put this update query? on profile.php/login/logout please help me. Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-842189 Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi Firstly, do you want them to log out / be regarded as logged out after 15 minutes or 2 hours? Seems a bit strange to use the 2 seperate figures. 1) user dont have to log in again and again till he/ she himself/herself dont want to do log out No need for them to do that if you check the last_access date. You merely automatically update the last access date every time they access a page, as long as they have not left it too long (ie, catch out where someone has walked off leaving themselves logged in and half an hour later someone else comes along and decides to cause mischief on the PC). 2)before 15 minutes,if user want to do log out then he/she can simply do log out and leave. Again same can be done by setting last_access to a date / time in the past. if this condition satisfies than just change the status of that particular user to 0. but got stucked with where to put this update query? on profile.php/login/logout Depends. If you do it on any of the scripts you have then you would have to do it for everyone (which has no advantage over doing it on timestamps), or for that particular user (which would be pretty useless). If it was a heavily used script (ie, people logging in and out all the time) then you could do it for everyone, but from the login script. So that every time a new person logs in those not using the system are logged out at the same time. If it is a lightly used script then just put it in a common routine that is included at the top of every page. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-842198 Share on other sites More sharing options...
deepson2 Posted May 26, 2009 Author Share Posted May 26, 2009 Seems a bit strange to use the 2 seperate figures. I am sorry i was considering 15 minutes here only. $sSqlSec = "Update ".tbl_author." Set last_access = NOW() where id='$userid' and TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15"; $resultSec = mysql_query($sSqlSec,$conn) or die(mysql_error()); if (mysql_affected_rows() < 1) { header('Location:../Logout.php'); // Or do something else should they not have done anything in the last 15 mins exit(); } In your query i can see there is no status value. do you mean to say that i can do this without updating status value? still if someone left as soon as he/she comes( 5 seconds) then do he/she will be shown online for 15 minutes onward since they logged in? Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-842203 Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi I see no real need for a status value. If someone leaves as soon as they come in then you just set their last_access to some time in the past (eg, 1st Jan 1970) as part of the log out script. If you want to keep last_access as the date / time they last logged in then just use an extra column to record when they last did anything. That update statement both keeps the last_access up to date and lets you know if they haven't touched anything recently (ie, if the time they last touched anything is more than 15 mins ago then the row isn't updated, hence no rows affected). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-842207 Share on other sites More sharing options...
deepson2 Posted May 26, 2009 Author Share Posted May 26, 2009 Lets consider everything(update and select) i have to do it on profile.php (because where actually i want to show user's status whether he/she is online or not) If someone leaves as soon as they come in then you just set their last_access to some time in the past (eg, 1st Jan 1970) as part of the log out script. how can i set that? i mean where in update query or selection query? If you want to keep last_access as the date / time they last logged in then just use an extra column to record when they last did anything. Again how to do that? what is need of doing this? please explain this to me. Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-842224 Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi Put the following near the start of profile.php (and in any other script except for login.php and logout.php):- $sSqlSec = "Update ".tbl_author." Set last_access = NOW() where id='$userid' and TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15"; $resultSec = mysql_query($sSqlSec,$conn) or die(mysql_error()); if (mysql_affected_rows() < 1) { header('Location:logout.php'); // Or do something else should they not have done anything in the last 15 mins exit(); } Also in profile.php, where you want a list of those users and whether they are logged in or out:- $res = $op->runsql("SELECT username, CASE WHEN TIMESTAMPDIFF( MINUTE, last_access, CURRENT_TIMESTAMP ) <= 15 THEN 'online' ELSE 'offline' END AS status FROM ".tbl_author." "); while($row1 = $op->select($res)) { echo $row1['username']." - ".$row1['status']."<br />"; } In login.php, set last_access = NOW() for a user when they log in (after you have checked their password, etc):- $result12 = $op->runsql("UPDATE ".tbl_author." SET last_access = NOW() WHERE username='$username' AND password='".md5($passwd)."'"); In logout.php $update = $op->runsql("UPDATE ".tbl_author." SET last_access = '0000-00-00 00:00:00' WHERE id = '$userid'"); All theb est Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-842252 Share on other sites More sharing options...
deepson2 Posted May 28, 2009 Author Share Posted May 28, 2009 Hello keith, I am so sorry, reply here late. my net was down :'( and i could not see what you have suggested to me. just now i saw that. and checked it. its working like charm!!!! still i ll check it till 15 minutes and let you know.(i couldn't resist myself to check it before telling you here that its working) thanks a lot!!!!!! just waiting for 15 minutes and ll let you know ok. Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-844072 Share on other sites More sharing options...
deepson2 Posted May 28, 2009 Author Share Posted May 28, 2009 there are two problems- 1) when i do sudden logged out (let's say after 5 minutes) its still showing me user as online. 2) after 15 minutes, though i do refresh my page twice. its not considering that and showing me offline. any help? Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-844089 Share on other sites More sharing options...
kickstart Posted May 28, 2009 Share Posted May 28, 2009 Hi Take it you have phpMyAdmin. If so then check that when you do anything the last_access on the author table is being updated. Also check that when you log out the last_access is set to some old date / time or zeros. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-844096 Share on other sites More sharing options...
deepson2 Posted May 28, 2009 Author Share Posted May 28, 2009 there are 2 point we need to consider here. as i want to see/show on profile page that who is logged in or not. so there must be to user we need to consider. 1) who is logged in( $userid) 2)a user who's profile is being watched by $userid and that user would be $blogdata->author. for update on proflle.php $sSqlSec = "Update ".tbl_author." Set last_access = NOW() where id='$userid' "; if(mysql_num_rows($sSqlSec) < 1){ //$resultSec = mysql_query($sSqlSec,$conn) or die(mysql_error()); //header('Location:logout.php'); // Or do something else should they not have done anything in the last 15 minsexit(); } and for seletion. it should be somthing like this. $res = $op->runsql("SELECT CASE WHEN TIMESTAMPDIFF( MINUTE, last_access, CURRENT_TIMESTAMP ) <= 15 THEN 'online' ELSE 'offline' END AS status FROM ".tbl_author." where id='$blogdata->author' "); if(mysql_num_rows($sSqlSec) > 0){ echo "online"; else{ echo "offline"; } do you really think its necessary to update last access on login.php? because we are checking it on profile.php..so we can update it on profile.php only. what you say? as you said i checked it. but its updating only when user is logged in through login.php. its not updating any new time on profile.php. neither its setting any old time while i did the logout. Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-844118 Share on other sites More sharing options...
kickstart Posted May 28, 2009 Share Posted May 28, 2009 Hi In profile.php do this:- $sSqlSec = "Update ".tbl_author." Set last_access = NOW() where id='$userid' and TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15"; $resultSec = mysql_query($sSqlSec,$conn) or die(mysql_error()); if (mysql_affected_rows() < 1) { header('Location:logout.php'); // Or do something else should they not have done anything in the last 15 mins exit(); } Idea is that it will only update the last_access for the user if the last_access was already within the last 15 mins. If last_access was over 15 mins ago then the row is not updated, hence mysql_affected_rows() returns 0 and you redirect the user away. You method would just set last_access whether you want to regard them as logged off or not. Fine if you just want people to instantly log in again, but no good if you want to force those who have been inactive to log in again. With this code:- $res = $op->runsql("SELECT CASE WHEN TIMESTAMPDIFF( MINUTE, last_access, CURRENT_TIMESTAMP ) <= 15 THEN 'online' ELSE 'offline' END AS status FROM ".tbl_author." where id='$blogdata->author' "); if(mysql_num_rows($sSqlSec) > 0){ echo "online"; else{ echo "offline"; } you are getting the status of a particular user. That status will be in a field on a row returned with a value of 'online' or 'offline'. However all you are checking is the number of rows returned and if one or more rows are returned you say they are online. If the user exists it will return a row so your code will always regard them as online. The only way they would come back as being offline is if $blogdata->author wasn't in "tbl_author". All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-844151 Share on other sites More sharing options...
deepson2 Posted May 29, 2009 Author Share Posted May 29, 2009 Hello keith, I have tried your both the queries. selection is perfect but for updation i made small change. like this $sSqlSec = $op->runsql("Update ".tbl_author." Set last_access = NOW() where id='$userid'"); i have removed this part and TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15";ltSec = mysql_query($sSqlSec,$conn) or die(mysql_error()); if (mysql_affected_rows() < 1) { header('Location:logout.php'); // Or do something else should they not have done anything in the last 15 mins exit(); } because it was going directly to my logout page. Now what is working. its as bellow selection query is like this- (made small chages) $res = $op->runsql("SELECT CASE WHEN TIMESTAMPDIFF( MINUTE, last_access, CURRENT_TIMESTAMP ) <= 15 THEN 'online' ELSE 'offline' END AS status FROM ".tbl_author." where id='$blogdata->author'"); if(mysql_num_rows($res) > 0){ while($row1 = $op->select($res)){ if($row1['status'] =='online'){ echo "online"; }else{ echo "offline"; } } } 1) I am updating last_access time on only profile.php so its working. after 15 minutes if user is being inactive on page it showing me that user as offline. Now what i want and what is happeing.-- happeing-after 15 minutes its showing me user as offline but as soon as that user refreshes his/her profile page its showing me again user is online. what i want--if after 15 minutes if user is not active on page though he/she refresh profile.php,redirect him/her on login.php to do login again. i am trying. but please suggest me something. Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-844793 Share on other sites More sharing options...
kickstart Posted May 29, 2009 Share Posted May 29, 2009 what i want--if after 15 minutes if user is not active on page though he/she refresh profile.php,redirect him/her on login.php to do login again. i am trying. but please suggest me something. That is what the bit of code you removed was to do. $sSqlSec = "Update ".tbl_author." Set last_access = NOW() where id='$userid' and TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15"; $resultSec = mysql_query($sSqlSec,$conn) or die(mysql_error()); if (mysql_affected_rows() < 1) { header('Location:logout.php'); // Or do something else should they not have done anything in the last 15 mins exit(); } What it is doing is only updating the user if they last did anything 15 or less minutes ago. If someone last did anything 20 minutes ago then the update will not do anything, hence the mysql_affected_rows will be 0. As such it would redirect them to the logout page (you could change it to login.php if you wanted). The code should work (I have pretty much the same code in a few systems). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-844889 Share on other sites More sharing options...
deepson2 Posted May 30, 2009 Author Share Posted May 30, 2009 hello keith, this code is not working for me. it derectly goes to the logout page. that we dont want right? $sSqlSec = "Update ".tbl_author." Set last_access = NOW() where id='$userid' and TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15"; $resultSec = mysql_query($sSqlSec,$conn) or die(mysql_error()); if (mysql_affected_rows() < 1) { header('Location:logout.php'); // Or do something else should they not have done anything in the last 15 mins exit(); } I wanted to ask you this. is this the best method to show user is online on site not on single page? i have discussed this with my senior. then he said user should be online for the whole site not on the only one page.like index.php and others also. you can not consider the logic(15 min for only profile page). what if user has done the logged in and is busy with the other pages on site so how can he would be shown offline to other user who are watching his profile?(make sense right?) so is there any dynamic way(may be using session) to check that logged in user is online for the whole site not on the single page? please help me. Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-845662 Share on other sites More sharing options...
Garethp Posted May 30, 2009 Share Posted May 30, 2009 Here's my idea, have a php file included at the top of every file (It's what I do, to connect to the database and start session) and each time that script it run, set a column to NOW() and if they logout, set that column to 1, and when you check if they are only, just select the user and check if the column value is more than NOW() - (60*15), which should be NOW() - 15 Minutes. That way, whenever they use any part of your site, their online is set to that moment, and they will be seen as online if they used it anytime in the last 15 minutes Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-845667 Share on other sites More sharing options...
kickstart Posted May 30, 2009 Share Posted May 30, 2009 hello keith, this code is not working for me. it derectly goes to the logout page. that we dont want right? Not sure, but the best thing to do is to use that SQL in phpmyadmin and check it works. However, you are changing $conn to whatever is your connect to the database aren't you? I wanted to ask you this. is this the best method to show user is online on site not on single page? i have discussed this with my senior. then he said user should be online for the whole site not on the only one page.like index.php and others also. you can not consider the logic(15 min for only profile page). what if user has done the logged in and is busy with the other pages on site so how can he would be shown offline to other user who are watching his profile?(make sense right?) That is why you put the check for whether they are logged in / set the time since they last did anything at the top of all you pages (probably put it in an include) as suggested originally. All that doing the update and check of the number of rows affected like that manages is to save having to perform a seperate SELECT to check they are still logged in and then a seperate UPDATE. Here's my idea, have a php file included at the top of every file (It's what I do, to connect to the database and start session) and each time that script it run, set a column to NOW() and if they logout, set that column to 1, and when you check if they are only, just select the user and check if the column value is more than NOW() - (60*15), which should be NOW() - 15 Minutes. That way, whenever they use any part of your site, their online is set to that moment, and they will be seen as online if they used it anytime in the last 15 minutes That is the whole point of the code he is using. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-845705 Share on other sites More sharing options...
deepson2 Posted May 30, 2009 Author Share Posted May 30, 2009 Not sure, but the best thing to do is to use that SQL in phpmyadmin and check it works. and TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15 We can not keep where condition in update(thats what i think) so when i tried your query its only updating my last_access column with Now() and then its directly gonig to logout.php. dont know why? and secondly That is why you put the check for whether they are logged in / set the time since they last did anything at the top of all you pages (probably put it in an include) as suggested originally. all we are doing this for only one page. if as per the your suggestion if i put my selection query on each page where i really want to show that this user is online. than dont you thing it would be its limitation that suppose my profile.php's last_access time is different than index.php( i am confused)..but it wont happend, because i have only one last_access column..yes..so it will be updating every time no matter whether he/she is on index or profile. right? i am confused again. ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-845715 Share on other sites More sharing options...
kickstart Posted May 30, 2009 Share Posted May 30, 2009 We can not keep where condition in update(thats what i think) so when i tried your query its only updating my last_access column with Now() and then its directly gonig to logout.php. dont know why? You can keep the where condition in the update. No reason why it will not work. If it is updating the column then mysql_affected_rows() should return 1, so the redirect should not happen. Comment out the redirect and echo out mysql_affected_rows(). Check it really is 1. all we are doing this for only one page. if as per the your suggestion if i put my selection query on each page where i really want to show that this user is online. than dont you thing it would be its limitation that suppose my profile.php's last_access time is different than index.php( i am confused)..but it wont happend, because i have only one last_access column..yes..so it will be updating every time no matter whether he/she is on index or profile. right? Generally don't think you would care about last_access being different for each page (and if you did you would want to put the last access time on a seperate table so you wouldn't need to add a new column every time you added a new page). If you want to check someone is still logged in then it doesn't really matter which page they last used, just as long as they used a page within the last 15 minutes. So every page can update the same last_access field. Can you post the full profile.php script? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-845727 Share on other sites More sharing options...
deepson2 Posted May 30, 2009 Author Share Posted May 30, 2009 If you want to check someone is still logged in then it doesn't really matter which page they last used, just as long as they used a page within the last 15 minutes. So every page can update the same last_access field. 1)you mean to say if we are updating last_access on profile.php and i would be inactive for that page more than 15 minutes.and searching other pages. so what ll others can see exactly on profile page of min2? 2) dont you think that logged in user must be wondering that i am very much active on the site then still why profile page is asking me to do login again? well i am dumping my code here. i dont know how much you ll get it properly. <? ob_start(); include("includes/config.php"); include("functions.php"); //ini_set( "display_errors", 0); $retval = retpath(); usersess(); $uid = $userid; $authorinfo = $blog->personaldata(); $usrname = $_REQUEST['usrname']; $resuid = mysql_query("SELECT id, username FROM ".tbl_author." WHERE username='".$usrname."'"); $rowuid = mysql_fetch_row($resuid); $uid=$rowuid[0]; $blogdata = $blog->personaldata(); $retpath = retpath(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" type="text/css" href="<?=$retpath;?>/includes/adda2.css" media="screen" /> <script type="text/javascript" language="javascript" src="<?=$retpath;?>/includes/functions.js"></script> <link href="../style.css" rel="stylesheet" type="text/css" /> <!-- jQuery library --> <script type="text/javascript" src="<?=$retpath;?>/lib/jquery-1.2.3.pack.js"></script> <!-- jCarousel library --> <script type="text/javascript" src="<?=$retpath;?>/lib/jquery.jcarousel.pack.js"></script> <!-- jCarousel core stylesheet --> <link rel="stylesheet" type="text/css" href="<?=$retpath;?>/lib/jquery.jcarousel.css" /> <!-- jCarousel skin stylesheet --> <link rel="stylesheet" type="text/css" href="<?=$retpath;?>/skins/tango/skin.css" /> <style type="text/css"> /** * Overwrite for having a carousel with dynamic width. */ .jcarousel-skin-tango .jcarousel-container-horizontal { xwidth: 100%; } .jcarousel-skin-tango .jcarousel-clip-horizontal { width: 100%; } </style> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#mycarousel').jcarousel({ visible: 3 }); }); </script> </head> <?if(!$userid){?> <body id="free"> <?}else{ ?> <body> <?}?> <div id="wrapper"> <div id="header"><? include("templates/header.tpl"); ?></div> <!-- Header ends --> <? include("templates/banner.tpl"); ?> <div id="mainContent"><div class="blogcontainer"> <?if($blogdata->username==""){ ?> <p> </p> <div id="artMsg"><?=$usrname;?> does not exist on blogadda.<br />If you want <?=$usrname;?> as your username, <a href="/register">grab it now</a></div> <?}else{?> <? $imagearr = explode(",",$blogdata->avatar); ?> <div class="prAvatar"><img src="<?=$retpath;?>/<?=$imagearr[0];?>" width="83" height="83" alt="<?=ucfirst($blogdata->username); ?> - Avatar" /></div> <div class="prName"> <h2><?=ucfirst($blogdata->username); ?>'s profile</h2><?if(!$userid){ ?> <p>Please <a href='/login'>login</a> to view more details about <?=ucfirst($blogdata->username); ?></p></div> <?}else{ $sSqlSec = $op->runsql("Update ".tbl_author." Set last_access = NOW() where id='$userid' AND TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15"); if(mysql_num_rows($sSqlSec) <=1) { //header('Location:logout.php'); // Or do something else should they not have done anything in the last 15 mins exit(); } //$check =$op->runsql("select * from author where $result = $op->runsql("SELECT a.username,b.id, b.title, b.url,a.status, b.descr, b.blogpath, a.fname as fullname, LEFT(b.descr, 200) as newdescr, a.status FROM ".tbl_bloginfo." b,".tbl_author." a WHERE (b.author = a.id) AND a.id = '$uid' AND b.approve !='P' ORDER BY b.id DESC"); if(mysql_num_rows($result) > 0){ if(mysql_num_rows($result)>0){ while($row1 = $op->select($result)){ $bloglist[$i]=$row1['title']; $blogurl[$i]=$row1['blogpath']; $i++;} }else{ $row = $op->select($result); ?> <? } } ?> </div> <div id="userProfile"> <? ?> <ul class="nav"> <!--<li><img src="<?=$retpath;?>/images/<?if($blogdata->gender=='M'){ echo 'icon_boy.gif';}else if($blogdata->gender=='F'){ echo 'icon_girl.gif';} ?>" width="20" height="14" alt="<?if($blogdata->gender=='M'){ echo 'Male';}else if($blogdata->gender=='F'){ echo 'Female';}?>" /> <?=$blogdata->fullname; if($blogdata->authoredby=='M'){ echo" Multi author";} ?></li> --> <li><span class="<?if($blogdata->gender=='M'){ echo 'male';}else if($blogdata->gender=='F'){ echo 'female';} ?>"><? echo $blogdata->fullname; if($blogdata->authoredby=='M'){ echo" Multi author";} ?></span></li> <li><span class="DOB"><?=date('d M', strtotime($blogdata->birthdt));?> </span></li> <li class="last"><span class="city"><?=$blogdata->city?></span></li> <!--<li><img src="<?=$retpath;?>/images/icon_birthday.gif" width="20" height="16" alt="DOB" /> <?=date('d M', strtotime($blogdata->birthdt));?></li> --> <!--<li class="last"><img src="<?=$retpath;?>/images/icon_city.gif" width="20" height="16" alt="City" /> <?=$blogdata->city?></li> --> </ul> </div> <? $blogcount=count($bloglist); if($blogcount>0){?> <h3 class="interestText">My Blog(s)</h3> <ul class="myaccountNav"> <?for ($j = 0; $j <$blogcount; $j++) { echo "<li><a href='/blogs/".$blogurl[$j]."'>".ucfirst(strtolower(stripslashes($bloglist[$j])))."</a></li>"; } ?></ul><? }if($blogdata->about!=""){?> <h3 class="abtinterestText">About me</h3> <p><?=stripslashes($blogdata->about);?></p> <?} ?> <?if($blogdata->interest!=""){?> <h3 class="interestText">My Interest</h3> <p><?=stripslashes($blogdata->interest);?></p> <?} echo "SELECT CASE WHEN TIMESTAMPDIFF( MINUTE, last_access, CURRENT_TIMESTAMP ) <= 15 THEN 'online' ELSE 'offline' END AS status FROM ".tbl_author." where id='$blogdata->author'"; $res = $op->runsql("SELECT CASE WHEN TIMESTAMPDIFF( MINUTE, last_access, CURRENT_TIMESTAMP ) <= 15 THEN 'online' ELSE 'offline' END AS status FROM ".tbl_author." where id='$blogdata->author'"); if(mysql_num_rows($res) > 0){ while($row1 = $op->select($res)){ if($row1['status'] =='online'){ echo "online"; }else{ echo "offline"; } } } ?> <?if($err_msg!=""){ ?><p class='fade' id='artMsg'><?=$err_msg; ?></p> <?}?> <? ?> <h3 class="interestText">Recent Visitor's</h3> <? if($blogdata->author != $userid){ //echo $from; $query = $op->insert( "INSERT INTO recent_visitor (profile_owner, visitor_id, first_visited, recent_visited, visiting_count) VALUES ('".$blogdata->author."', '".$userid."', NOW(), NOW(), 1) ON DUPLICATE KEY UPDATE `visiting_count`=`visiting_count`+1"); if($query > 0){ $err_msg_shout="Shout Posted"; }else{ $err_msg_shout="Error, Try Again"; } } ?> <ul id="mycarousel" class="jcarousel-skin-tango"> <? //if($userid == $blogdata->author){ //echo "SELECT a.username,a.avatar,r.visitor_id,r.visiting_count,TIMESTAMPDIFF(MINUTE, r.recent_visited, NOW()) AS MinsSinceLastVisit FROM recent_visitor as r ,author as a WHERE (r.visitor_id = a.id) AND r.profile_owner = '$userid' ORDER BY r.recent_visited DESC "; $sqlpage = $op->runsql("SELECT a.username,a.avatar,r.visitor_id,r.visiting_count,TIMESTAMPDIFF(MINUTE, r.recent_visited, NOW()) AS MinsSinceLastVisit FROM recent_visitor as r ,author as a WHERE (r.visitor_id = a.id) AND r.profile_owner = '$blogdata->author' ORDER BY r.recent_visited desc "); if(mysql_num_rows($sqlpage) > 0){ while($row1 = $op->select($sqlpage)){ // $minutes_dif = $row1['MinsSinceLastVisit']; $imagearr = explode(",",$row1['avatar']); $imagearr[0]= preg_replace("/\/avatar\//","/small/", $imagearr[0]); //$userName = $row1['username']; //$uri = '/profile/'.$blog->spacereplace($userName); // $uriImage = $retpath.'/'.$imagearr[0]; ?> <li><a href="/profile/<?=$blog->spacereplace($row1['username']);?>/" title="<?=$row1['username']?>"><img src="<?=$retpath;?>/<?=$imagearr[0];?>" width="50" height="50" alt="" /></a><? $minutes_dif = $row1['MinsSinceLastVisit']; $Ymin = 60 * 24 * 365; $Mmin = 60 * 24 * 30; $Wmin = 60 * 24 * 7; $Dmin = 60 * 24; $Hmin = 60; $Y = (int)($minutes_dif / $Ymin); $minutes_dif = $minutes_dif % $Ymin; $MON = (int)($minutes_dif / $Mmin); $minutes_dif = $minutes_dif % $Mmin; $W = (int)($minutes_dif / $Wmin); $minutes_dif = $minutes_dif % $Wmin; $D = (int)($minutes_dif / $Dmin); $minutes_dif = $minutes_dif % $Dmin; $H = (int)($minutes_dif / $Hmin); $minutes_dif = $minutes_dif % $Hmin; if($Y > 0 ){ echo "$Y year(s) "; }else if($MON > 0){ echo "$MON month(s) "; } else if($W > 0){ echo "$W week(s) "; } else if($D > 0){ echo "$D day(s) "; } else if($H > 0){ echo "$H hour(s) "; } else if($minutes_dif > 0) echo "$minutes_dif minute(s) "; else if($minutes_diff <= 0) echo "A minute "; echo "ago"; ?>(<?=$row1['visiting_count']?>visits)<? echo"\t"; ?> </li> <? }}?> </ul> <?}} ?> <p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p> </div> <!-- blog conatiner ends --> <div class="profileLeft"> <h3 class="shoutboxTitle">My Shoutbox</h3> <? if(!$userid){ ?> <p>To view and post on <b><?=ucfirst($blogdata->username); ?>'s shoutbox</b>, You need to <a href='/login'>login</a></p> <?} else { $result = $op->runsql("SELECT count(*) as cnt FROM ".tbl_author." a JOIN ".tbl_message ." m ON a.id = m.fromid where m.toid='".$blogdata->author."'"); $limit_value = 2; $ts = mysql_fetch_array($result); $total_records = $ts['cnt']; $top = $total_records / $limit_value; $total_pages = ceil($top); $start = $_REQUEST['start'] == "" ? 0 : $_REQUEST['start']; $sqlpage = $op->runsql("SELECT m.messageid,a.username,m.message,m.date FROM ".tbl_author." a JOIN ".tbl_message ." m ON a.id = m.fromid where m.toid='".$blogdata->author."' ORDER BY m.messageid DESC LIMIT $start, $limit_value"); if(mysql_num_rows($sqlpage) > 0){ ?> <p class="msgText">Total <strong><?=$total_records;?></strong><?if($total_records<1){?> Message<?}else{?> Messages<?}?></p> <?if($err_msg_shout!=""){?><p class='fade' id='shoutMsg'><?=$err_msg_shout; ?></p> <?} while($row1 = $op->select($sqlpage)){ ?> <div class="friends" id='delMsg<?=$row1['messageid'];?>'> <h4 ><a href='/profile/<?=$row1['username'];?>'><?=$row1['username'];?></a> says:</h4> <?if($authorinfo->author == $blogdata->author){?><span><a href="javascript: msgdelete(<?=$row1['id'];?>);" title="X">X</a></span><?}?> <p><?=$row1['message']; ?></p> <h5><?=date('d-m-Y', strtotime($row1['date']));?></h5> </div><!-- shout box ends --> <? } /*------Paging starts-----*/ $redirect = "/profile/$usrname"; if($total_records > $limit_value){ echo "<div class='shoutboxPage'>"; msg_paging($total_records, $total_rows, $limit_value, $start, $page, $total_pages, $redirect); echo "</div>"; /*-------Paging ends------*/ } } mysql_free_result($result); mysql_free_result($sqlpage); //if($authorinfo->author != $blogdata->author){ ?> <div class="profileLeft"> <h3 class="shoutboxTitle">Friends</h3> <? if(!$userid){ ?> <p>To view and post on <b><?=ucfirst($blogdata->username); ?>'s shoutbox</b>, You need to <a href='/login'>login</a></p> <?} else { $result = $op->runsql("SELECT count(*) as cnt FROM ".tbl_author." a JOIN ".tbl_friends ." m ON a.id = m.myfriends where (m.myname = '$blogdata->author') AND (m.status='F' OR m.status='M')"); $result1 = $op->runsql("SELECT count(*) as cnt FROM author a JOIN friends m ON a.id = m.myname WHERE ( m.myfriends = '$blogdata->author' ) AND ( m.status = 'M')"); $limit_value = 10; $ts = mysql_fetch_array($result); $ts1 = mysql_fetch_array($result1); $total_records = $ts['cnt']+$ts1['cnt']; $top = $total_records / $limit_value; $total_pages = ceil($top); $start = $_REQUEST['start'] == "" ? 0 : $_REQUEST['start']; $imagarr=array(); $i=0; if( $to= $userid) { $sqlpage = $op->runsql("SELECT m.id as mid,a.avatar,m.myname,m.myfriends, a.username,m.status FROM ".tbl_author." a JOIN ".tbl_friends ." m ON a.id = m.myfriends where (m.myname = '$blogdata->author') AND (m.status='F' OR m.status='M') UNION SELECT m.id as mid, a.avatar, m.myname, m.myfriends, a.username,m.status FROM author a JOIN friends m ON a.id = m.myname WHERE ( m.myfriends = '$blogdata->author' ) AND ( m.status = 'M' ) ORDER BY mid desc LIMIT $start, $limit_value"); if(mysql_num_rows($sqlpage) > 0){ ?> <p class="msgText">Total <strong><?=$total_records;?></strong><?if($total_records >0){ ?> friend's<?}else{?> friend<?}}}?></p> <? if(mysql_num_rows($sqlpage) > 0){ while($row1 = $op->select($sqlpage)){ $imagearr = explode(",",$row1['avatar']); $imagearr[0]= preg_replace("/\/avatar\//","/small/", $imagearr[0]); ?> <a href='/profile/<?=$blog->spacereplace($row1['username']);?>/' title="<?=$row1['username']?>"><img src="<?=$retpath;?>/<?=$imagearr[0];?>" width="40" height="40" alt="<?=$row1['username']?>"/></a>status="<?=$row1['status']?>" <? echo"<br />"; $i++; } } } ?> <?if($authorinfo->author == $blogdata->author){?><?} ?> </div><!-- shout box ends --> <div class="profileLeft"> <h3 class="shoutboxTitle">My Fan's List</h3> <? if(!$userid){ ?> <p>To view and post on <b><?=ucfirst($blogdata->username); ?>'s shoutbox</b>, You need to <a href='/login'>login</a></p> <?} else { $result = $op->runsql("SELECT count(*) as cnt FROM ".tbl_friends." b,".tbl_author." a WHERE (b.myname = a.id) AND b.myfriends = '$uid' AND b.status='F'"); $limit_value = 10; $ts = mysql_fetch_array($result); $total_records = $ts['cnt']; $top = $total_records / $limit_value; $total_pages = ceil($top); $start = $_REQUEST['start'] == "" ? 0 : $_REQUEST['start']; $imagarr=array(); $i=0; $sqlpage = $op->runsql("SELECT a.username,a.avatar, b.myname FROM ".tbl_friends." b,".tbl_author." a WHERE (b.myname = a.id) AND b.myfriends = '$uid' AND b.status='F' ORDER BY b.myfriends DESC LIMIT $start, $limit_value"); if(mysql_num_rows($sqlpage) > 0){ ?> <p class="msgText">Total <strong><?=$total_records;?></strong><?if($total_records >1){ ?> fan's<?}else{?> fan<?}}}?></p> <? if(mysql_num_rows($sqlpage) > 0){ while($row1 = $op->select($sqlpage)){ $imagearr = explode(",",$row1['avatar']); $imagearr[0]= preg_replace("/\/avatar\//","/small/", $imagearr[0]); ?> <a href='/profile/<?=$blog->spacereplace($row1['username']);?>/' title="<?=$row1['username']?>"><img src="<?=$retpath;?>/<?=$imagearr[0];?>" width="40" height="40" alt="<?=$row1['username']?>"/></a> <? echo"\t"; $i++; } } ?> <?if($authorinfo->author == $blogdata->author){?><?} ?> </div><!-- shout box ends --> <form name="messageFrm" action="<?$PHP_SELF;?>" method="post"> <fieldset class="post2shoutBox"> <input type="hidden" name="to" value="<?=$blogdata->author;?>" /> <input type="hidden" name="from" value="<?=$userid;?>" /> <label for="comname">Name</label> <div><input type="text" name="comname" id="comname" size="25" readonly="readonly" value="<?=$authorinfo->username;?>" class="textfield" /><label class="errorText" id="validName"><?=$comnameErr;?></label></div> <label for="message">Message</label> <div><textarea name="message" id="message" cols="20" rows="4" class="textfield" onKeypress="textCounter(this,150);"><?=$message;?></textarea></div> </fieldset> <div class="fm-submit"><input type="submit" name="shout" value="Shout" class="shoutBtn" onClick="javascript:return validateMsg(messageFrm);"/></div> <fieldset class="post2shoutBox"> <input type="hidden" name="to" value="<?=$blogdata->author;?>" /> <input type="hidden" name="from" value="<?=$userid;?>" /> <?php if($blogdata->author!=$userid){ $result = $op->runsql("SELECT * FROM ".tbl_friends." as f WHERE ((f.myname = '$blogdata->author' AND f.myfriends = '$userid' AND f.status='M' ) OR (f.myname = '$userid' AND f.myfriends = '$blogdata->author' AND f.status='M' ) )"); $sql = $op->runsql("SELECT * FROM `friends` WHERE ((`myname` = '$to' AND `myfriends` = '$from' ) AND (status='F'))"); $showstatus = mysql_fetch_array($result); if(mysql_num_rows($result) > 0){ ?> <div class="fm-submit"><input type="submit" name="friend" value="Reject" class="shoutBtn" onClick="javascript:return validateMsg(messageFrm);"/></div> <?}else{ ?> <div class="fm-submit"><input type="submit" name="friend" value="AddasFriend" class="shoutBtn" onClick="javascript:return validateMsg(messageFrm);"/></div> <?} } ?> </form> <br class="clear" /> <?}?> </div> <!-- leftContent ends --> </div><!-- Main Content ends --> </div> <!-- Wrapper ends --> <div id="footerNav"><? include("templates/footer.tpl"); ?></div> <!-- footer ends --> </body> </html> please help me. do you think this forum ll close this thread because now its more than 40 thread? Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-845738 Share on other sites More sharing options...
kickstart Posted May 30, 2009 Share Posted May 30, 2009 1)you mean to say if we are updating last_access on profile.php and i would be inactive for that page more than 15 minutes.and searching other pages. so what ll others can see exactly on profile page of min2? 2) dont you think that logged in user must be wondering that i am very much active on the site then still why profile page is asking me to do login again? That is why you put that code at the top of every other page. That way when they access any page their last_access time is updated. Having a look through your code now. Only thing is that you are using some different way of using the databases (eg, $op->runsql) and not sure what is hidden in that object. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-845746 Share on other sites More sharing options...
kickstart Posted May 31, 2009 Share Posted May 31, 2009 Hi I have had a look at the code and reformatted it so that (to me) it is more readable. Tried to get the statements to line up. Also removed a lot of the jumps into and out of php processing. There are still a few issues (eg, towards the bottom you have $showstatus = mysql_fetch_array($result);, but do not seem to do anything with $showstatus). I have moved the check to see if someone is still logged on up to the top. If they are not I have set the $userid field to blank, and I hope this would push you code into treating them as not being logged on (presume being a blog you want people who are not logged on to be able to read pages, just not update them). Hopefully this will work. However I am not sure on the object you are using to access MySQL and whether it might corrupt mysql_num_rows. Otherwise I cannot see why it wouldn't work. <?php ob_start(); include("includes/config.php"); include("functions.php"); //ini_set( "display_errors", 0); $retval = retpath(); usersess(); $uid = $userid; $authorinfo = $blog->personaldata(); $usrname = $_REQUEST['usrname']; $resuid = mysql_query("SELECT id, username FROM ".tbl_author." WHERE username='".$usrname."'"); $rowuid = mysql_fetch_row($resuid); $uid=$rowuid[0]; $blogdata = $blog->personaldata(); $retpath = retpath(); // Redirect anyone who is not logged on or who hasn't done anyting in the last 15 mins to the logout pageo $sSqlSec = $op->runsql("Update ".tbl_author." Set last_access = NOW() where id='$userid' AND TIMESTAMPDIFF(MINUTE, last_access,NOW()) <= 15"); if(mysql_num_rows($sSqlSec) <=1) { $userid = ""; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <link rel="stylesheet" type="text/css" href="<?=$retpath;?>/includes/adda2.css" media="screen" /> <script type="text/javascript" language="javascript" src="<?=$retpath;?>/includes/functions.js"></script> <link href="../style.css" rel="stylesheet" type="text/css" /> <!-- jQuery library --> <script type="text/javascript" src="<?=$retpath;?>/lib/jquery-1.2.3.pack.js"></script> <!-- jCarousel library --> <script type="text/javascript" src="<?=$retpath;?>/lib/jquery.jcarousel.pack.js"></script> <!-- jCarousel core stylesheet --> <link rel="stylesheet" type="text/css" href="<?=$retpath;?>/lib/jquery.jcarousel.css" /> <!-- jCarousel skin stylesheet --> <link rel="stylesheet" type="text/css" href="<?=$retpath;?>/skins/tango/skin.css" /> <style type="text/css"> /** * Overwrite for having a carousel with dynamic width. */ .jcarousel-skin-tango .jcarousel-container-horizontal { xwidth: 100%; } .jcarousel-skin-tango .jcarousel-clip-horizontal { width: 100%; } </style> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#mycarousel').jcarousel({ visible: 3 }); }); </script> </head> <body <?php echo (($userid) ? "" : 'echoid="free"'); ?> > <div id="wrapper"> <div id="header"> <?php include("templates/header.tpl"); ?> </div> <!-- Header ends --> <?php include("templates/banner.tpl"); ?> <div id="mainContent"> <div class="blogcontainer"> <?php if($blogdata->username=="") { echo "<p> </p>"; echo "<div id='artMsg'>$usrname does not exist on blogadda.<br />If you want $usrname as your username, <a href='/register'>grab it now</a></div>"; } else { $imagearr = explode(",",$blogdata->avatar); echo "<div class='prAvatar'><img src='".$retpath."/".$imagearr[0]."' width='83' height='83' alt='".ucfirst($blogdata->username)." - Avatar' /></div>"; echo "<div class='prName'>"; echo "<h2>".ucfirst($blogdata->username)."'s profile</h2>"; if(!$userid) { echo "<p>Please <a href='/login'>login</a> to view more details about ".ucfirst($blogdata->username)."</p></div>"; } else { //$check =$op->runsql("select * from author where $result = $op->runsql("SELECT a.username,b.id, b.title, b.url,a.status, b.descr, b.blogpath, a.fname as fullname, LEFT(b.descr, 200) as newdescr, a.status FROM ".tbl_bloginfo." b,".tbl_author." a WHERE (b.author = a.id) AND a.id = '$uid' AND b.approve !='P' ORDER BY b.id DESC"); if(mysql_num_rows($result)>0) { while($row1 = $op->select($result)) { $bloglist[$i]=$row1['title']; $blogurl[$i]=$row1['blogpath']; $i++; } } ?> </div> <div id="userProfile"> <ul class="nav"> <!--<li><img src="<?=$retpath;?>/images/<?if($blogdata->gender=='M'){ echo 'icon_boy.gif';}else if($blogdata->gender=='F'){ echo 'icon_girl.gif';} ?>" width="20" height="14" alt="<?if($blogdata->gender=='M'){ echo 'Male';}else if($blogdata->gender=='F'){ echo 'Female';}?>" /> <?=$blogdata->fullname; if($blogdata->authoredby=='M'){ echo" Multi author";} ?></li> --> <li><span class="<?if($blogdata->gender=='M'){ echo 'male';}else if($blogdata->gender=='F'){ echo 'female';} ?>"><? echo $blogdata->fullname; if($blogdata->authoredby=='M'){ echo" Multi author";} ?></span></li> <li><span class="DOB"><?=date('d M', strtotime($blogdata->birthdt));?> </span></li> <li class="last"><span class="city"><?=$blogdata->city?></span></li> <!--<li><img src="<?=$retpath;?>/images/icon_birthday.gif" width="20" height="16" alt="DOB" /> <?=date('d M', strtotime($blogdata->birthdt));?></li> --> <!--<li class="last"><img src="<?=$retpath;?>/images/icon_city.gif" width="20" height="16" alt="City" /> <?=$blogdata->city?></li> --> </ul> </div> <?php $blogcount=count($bloglist); if($blogcount>0) { echo '<h3 class="interestText">My Blog(s)</h3>'; echo '<ul class="myaccountNav">'; for ($j = 0; $j <$blogcount; $j++) { echo "<li><a href='/blogs/".$blogurl[$j]."'>".ucfirst(strtolower(stripslashes($bloglist[$j])))."</a></li>"; } echo "</ul>"; } if($blogdata->about!="") { echo'<h3 class="abtinterestText">About me</h3>'; echo '<p>'.stripslashes($blogdata->about).'</p>'; } if($blogdata->interest!="") { echo '<h3 class="interestText">My Interest</h3>'; echo '<p>'.stripslashes($blogdata->interest).'</p>'; } echo "SELECT CASE WHEN TIMESTAMPDIFF( MINUTE, last_access, CURRENT_TIMESTAMP ) <= 15 THEN 'online' ELSE 'offline' END AS status FROM ".tbl_author." where id='$blogdata->author'"; $res = $op->runsql("SELECT CASE WHEN TIMESTAMPDIFF( MINUTE, last_access, CURRENT_TIMESTAMP ) <= 15 THEN 'online' ELSE 'offline' END AS status FROM ".tbl_author." where id='$blogdata->author'"); if(mysql_num_rows($res) > 0) { while($row1 = $op->select($res)) { echo $row1['status']; } } if($err_msg!="") echo "<p class='fade' id='artMsg'>$err_msg;</p>"; echo "<h3 class='interestText'>Recent Visitor's</h3>"; if($blogdata->author != $userid) { //echo $from; $query = $op->insert( "INSERT INTO recent_visitor (profile_owner, visitor_id, first_visited, recent_visited, visiting_count) VALUES ('".$blogdata->author."', '".$userid."', NOW(), NOW(), 1) ON DUPLICATE KEY UPDATE `visiting_count`=`visiting_count`+1"); if($query > 0) { $err_msg_shout="Shout Posted"; } else { $err_msg_shout="Error, Try Again"; } } echo '<ul id="mycarousel" class="jcarousel-skin-tango">'; //if($userid == $blogdata->author){ //echo "SELECT a.username,a.avatar,r.visitor_id,r.visiting_count,TIMESTAMPDIFF(MINUTE, r.recent_visited, NOW()) AS MinsSinceLastVisit FROM recent_visitor as r ,author as a WHERE (r.visitor_id = a.id) AND r.profile_owner = '$userid' ORDER BY r.recent_visited DESC "; $sqlpage = $op->runsql("SELECT a.username,a.avatar,r.visitor_id,r.visiting_count,TIMESTAMPDIFF(MINUTE, r.recent_visited, NOW()) AS MinsSinceLastVisit FROM recent_visitor as r ,author as a WHERE (r.visitor_id = a.id) AND r.profile_owner = '$blogdata->author' ORDER BY r.recent_visited desc "); if(mysql_num_rows($sqlpage) > 0) { while($row1 = $op->select($sqlpage)) { // $minutes_dif = $row1['MinsSinceLastVisit']; $imagearr = explode(",",$row1['avatar']); $imagearr[0]= preg_replace("/\/avatar\//","/small/", $imagearr[0]); //$userName = $row1['username']; //$uri = '/profile/'.$blog->spacereplace($userName); // $uriImage = $retpath.'/'.$imagearr[0]; echo '<li><a href="/profile/'.$blog->spacereplace($row1['username']).'/" title="'.$row1['username'].'"><img src="'.$retpath.'/'.$imagearr[0].'" width="50" height="50" alt="" /></a>'; $minutes_dif = $row1['MinsSinceLastVisit']; $Ymin = 60 * 24 * 365; $Mmin = 60 * 24 * 30; $Wmin = 60 * 24 * 7; $Dmin = 60 * 24; $Hmin = 60; $Y = (int)($minutes_dif / $Ymin); $minutes_dif = $minutes_dif % $Ymin; $MON = (int)($minutes_dif / $Mmin); $minutes_dif = $minutes_dif % $Mmin; $W = (int)($minutes_dif / $Wmin); $minutes_dif = $minutes_dif % $Wmin; $D = (int)($minutes_dif / $Dmin); $minutes_dif = $minutes_dif % $Dmin; $H = (int)($minutes_dif / $Hmin); $minutes_dif = $minutes_dif % $Hmin; if($Y > 0 ){ echo "$Y year(s) "; }else if($MON > 0){ echo "$MON month(s) "; } else if($W > 0){ echo "$W week(s) "; } else if($D > 0){ echo "$D day(s) "; } else if($H > 0){ echo "$H hour(s) "; } else if($minutes_dif > 0) echo "$minutes_dif minute(s) "; else if($minutes_diff <= 0) echo "A minute "; echo "ago(".$row1['visiting_count']."visits) \t"; echo '</li>'; } } echo '</ul>'; } } ?> <p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p> </div> <!-- blog conatiner ends --> <div class="profileLeft"> <h3 class="shoutboxTitle">My Shoutbox</h3> <?php if(!$userid) { echo "<p>To view and post on <b>".ucfirst($blogdata->username)."'s shoutbox</b>, You need to <a href='/login'>login</a></p>"; } else { $result = $op->runsql("SELECT count(*) as cnt FROM ".tbl_author." a JOIN ".tbl_message ." m ON a.id = m.fromid where m.toid='".$blogdata->author."'"); $limit_value = 2; $ts = mysql_fetch_array($result); $total_records = $ts['cnt']; $top = $total_records / $limit_value; $total_pages = ceil($top); $start = (($_REQUEST['start'] == "") ? 0 : $_REQUEST['start']); $sqlpage = $op->runsql("SELECT m.messageid,a.username,m.message,m.date FROM ".tbl_author." a JOIN ".tbl_message ." m ON a.id = m.fromid where m.toid='".$blogdata->author."' ORDER BY m.messageid DESC LIMIT $start, $limit_value"); if(mysql_num_rows($sqlpage) > 0) { echo '<p class="msgText">Total <strong>'.$total_records.'</strong> '.(($total_records <= 1) ? 'Message' : 'Messages').'</p>'; if($err_msg_shout!="") echo "<p class='fade' id='shoutMsg'>$err_msg_shout</p>"; while($row1 = $op->select($sqlpage)) { echo '<div class="friends" id="delMsg'.$row1['messageid'].'">'; echo '<h4 ><a href="/profile/'.$row1['username'].'">'.$row1['username'].'</a> says:</h4>'; if($authorinfo->author == $blogdata->author) echo '<span><a href="javascript: msgdelete('.$row1['id'].');" title="X">X</a></span>'; echo '<p>'.$row1['message'].'</p>'; echo '<h5>'.date('d-m-Y', strtotime($row1['date'])).'</h5>'; echo '</div><!-- shout box ends -->'; } /*------Paging starts-----*/ $redirect = "/profile/$usrname"; if($total_records > $limit_value) { echo "<div class='shoutboxPage'>"; msg_paging($total_records, $total_rows, $limit_value, $start, $page, $total_pages, $redirect); echo "</div>"; /*-------Paging ends------*/ } } mysql_free_result($result); mysql_free_result($sqlpage); //if($authorinfo->author != $blogdata->author){ echo '<div class="profileLeft">'; echo '<h3 class="shoutboxTitle">Friends</h3>'; if(!$userid) { echo '<p>To view and post on <b>'.ucfirst($blogdata->username)."'s shoutbox</b>, You need to <a href='/login'>login</a></p>"; } else { $result = $op->runsql("SELECT count(*) as cnt FROM ".tbl_author." a JOIN ".tbl_friends ." m ON a.id = m.myfriends where (m.myname = '$blogdata->author') AND (m.status='F' OR m.status='M')"); $result1 = $op->runsql("SELECT count(*) as cnt FROM author a JOIN friends m ON a.id = m.myname WHERE ( m.myfriends = '$blogdata->author' ) AND ( m.status = 'M')"); $limit_value = 10; $ts = mysql_fetch_array($result); $ts1 = mysql_fetch_array($result1); $total_records = $ts['cnt']+$ts1['cnt']; $top = $total_records / $limit_value; $total_pages = ceil($top); $start = $_REQUEST['start'] == "" ? 0 : $_REQUEST['start']; $imagarr=array(); $i=0; if( $to= $userid) { $sqlpage = $op->runsql("SELECT m.id as mid,a.avatar,m.myname,m.myfriends, a.username,m.status FROM ".tbl_author." a JOIN ".tbl_friends ." m ON a.id = m.myfriends where (m.myname = '$blogdata->author') AND (m.status='F' OR m.status='M') UNION SELECT m.id as mid, a.avatar, m.myname, m.myfriends, a.username,m.status FROM author a JOIN friends m ON a.id = m.myname WHERE ( m.myfriends = '$blogdata->author' ) AND ( m.status = 'M' ) ORDER BY mid desc LIMIT $start, $limit_value"); if(mysql_num_rows($sqlpage) > 0) { if($total_records >1) echo "<p class='msgText'>Total <strong>$total_records</strong> friend's</p>"; else echo "<p class='msgText'>Total <strong>$total_records</strong> friend</p>"; while($row1 = $op->select($sqlpage)) { $imagearr = explode(",",$row1['avatar']); $imagearr[0]= preg_replace("/\/avatar\//","/small/", $imagearr[0]); echo "<a href='/profile/".$blog->spacereplace($row1['username'])."/' title='".$row1['username']."'><img src='$retpath'/".$imagearr[0]."' width='40' height='40' alt='".$row1['username']."'/></a>status='".$row1['status']."'<br />"; $i++; } } } } echo '</div><!-- shout box ends -->'; echo '<div class="profileLeft">'; echo '<h3 class="shoutboxTitle">My Fan\'s List</h3>'; if(!$userid) { echo "<p>To view and post on <b>".ucfirst($blogdata->username)."'s shoutbox</b>, You need to <a href='/login'>login</a></p>"; } else { $result = $op->runsql("SELECT count(*) as cnt FROM ".tbl_friends." b,".tbl_author." a WHERE (b.myname = a.id) AND b.myfriends = '$uid' AND b.status='F'"); $limit_value = 10; $ts = mysql_fetch_array($result); $total_records = $ts['cnt']; $top = $total_records / $limit_value; $total_pages = ceil($top); $start = $_REQUEST['start'] == "" ? 0 : $_REQUEST['start']; $imagarr=array(); $i=0; $sqlpage = $op->runsql("SELECT a.username,a.avatar, b.myname FROM ".tbl_friends." b,".tbl_author." a WHERE (b.myname = a.id) AND b.myfriends = '$uid' AND b.status='F' ORDER BY b.myfriends DESC LIMIT $start, $limit_value"); if(mysql_num_rows($sqlpage) > 0) { echo '<p class="msgText">Total <strong>'.$total_records.'</strong>'.(($total_records >1) ? "fan's" : "fan").'</p>'; while($row1 = $op->select($sqlpage)) { $imagearr = explode(",",$row1['avatar']); $imagearr[0]= preg_replace("/\/avatar\//","/small/", $imagearr[0]); echo "<a href='/profile/".$blog->spacereplace($row1['username'])."/' title='".$row1['username']."'><img src='".$retpath."/".$imagearr[0]."' width='40' height='40' alt='".$row1['username']."/></a>\t"; $i++; } } } ?> </div><!-- shout box ends --> <form name="messageFrm" action="<?$PHP_SELF;?>" method="post"> <fieldset class="post2shoutBox"> <input type="hidden" name="to" value="<?=$blogdata->author;?>" /> <input type="hidden" name="from" value="<?=$userid;?>" /> <label for="comname">Name</label> <div><input type="text" name="comname" id="comname" size="25" readonly="readonly" value="<?=$authorinfo->username;?>" class="textfield" /><label class="errorText" id="validName"><?=$comnameErr;?></label></div> <label for="message">Message</label> <div><textarea name="message" id="message" cols="20" rows="4" class="textfield" onKeypress="textCounter(this,150);"><?=$message;?></textarea></div> </fieldset> <div class="fm-submit"><input type="submit" name="shout" value="Shout" class="shoutBtn" onClick="javascript:return validateMsg(messageFrm);"/></div> <fieldset class="post2shoutBox"> <input type="hidden" name="to" value="<?=$blogdata->author;?>" /> <input type="hidden" name="from" value="<?=$userid;?>" /> <?php if($blogdata->author!=$userid) { $result = $op->runsql("SELECT * FROM ".tbl_friends." as f WHERE ((f.myname = '$blogdata->author' AND f.myfriends = '$userid' AND f.status='M' ) OR (f.myname = '$userid' AND f.myfriends = '$blogdata->author' AND f.status='M' ) )"); $sql = $op->runsql("SELECT * FROM `friends` WHERE ((`myname` = '$to' AND `myfriends` = '$from' ) AND (status='F'))"); $showstatus = mysql_fetch_array($result); if(mysql_num_rows($result) > 0) { echo '<div class="fm-submit"><input type="submit" name="friend" value="Reject" class="shoutBtn" onClick="javascript:return validateMsg(messageFrm);"/></div>'; } else { echo '<div class="fm-submit"><input type="submit" name="friend" value="AddasFriend" class="shoutBtn" onClick="javascript:return validateMsg(messageFrm);"/></div>'; } } ?> </form> <br class="clear" /> <?php } ?> </div> <!-- leftContent ends --> </div><!-- Main Content ends --> </div> <!-- Wrapper ends --> <div id="footerNav"> <?php include("templates/footer.tpl"); ?> </div> <!-- footer ends --> </body> </html> All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-846188 Share on other sites More sharing options...
deepson2 Posted June 1, 2009 Author Share Posted June 1, 2009 Hello keith, Thanks for checking my whole code. $userid is my session value. so it cant be blank at times on page. it showing me do the login again. but now i understood what you are trying to say. so what is working now is as follows 1) user's logs in he/she ll be shown as logged in user 2) with each refreash/activation of the page. time is eexceeding and i have checked it. 3) if user logged off before 15 minutes it directly going to logout.php where i have set the last_access value to "0000-00-00 00:00:00" so the remaining issue was/is if user closes his/her browser what ll happend. so i was searching through net. got this link. please go through it. and give me your suggestion. http://www.sitepoint.com/forums/showthread.php?t=484838&highlight=online+offline+ajax Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-846757 Share on other sites More sharing options...
kickstart Posted June 1, 2009 Share Posted June 1, 2009 so the remaining issue was/is if user closes his/her browser what ll happend. so i was searching through net. got this link. please go through it. and give me your suggestion. To be honest, having people still reported as logged in for a few minutes if they just close the window is something I would just live with. While you can try and code around it there are a few issues. For example not sure that all browsers are going to trigger the onunload event in the same way when someone just closes a browser tab or shuts the browser down (let alone if they turn the power off, or lose a wireless connection), so likely this could cause some people to still be regarded as logged in when they aren't. Also it will only work if the user has javascript enabled. Lastly, what happens when people have multiple pages of your site open in different browser tabs (ie, with forums I tend to open a load of threads at once in the background and then read them once they have finished loading). You don't want to treat someone as logged off just because they closed one page of your site when they still had several open. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-846774 Share on other sites More sharing options...
deepson2 Posted June 1, 2009 Author Share Posted June 1, 2009 Lastly, what happens when people have multiple pages of your site open in different browser tabs (ie, with forums I tend to open a load of threads at once in the background and then read them once they have finished loading). You don't want to treat someone as logged off just because they closed one page of your site when they still had several open. yes that what i asked you day before yesterday about this. like i dont want to keep user online for one page but for the whole site. but now i can put my updation query on different pages so with that i can update my last_access time accordingly. For example not sure that all browsers are going to trigger the onunload event in the same way when someone just closes a browser tab or shuts the browser down (let alone if they turn the power off, or lose a wireless connection), so likely this could cause some people to still be regarded as logged in when they aren't. Also it will only work if the user has javascript enabled. you are absoultly right here. so lets leave this closing browser issue. if user forgot to logout and closes his/her browser it would be his/her lose right? making my code properly and keeping it into different forms as well. i thing issue is resolved now. thank you so much for being patient with me. Quote Link to comment https://forums.phpfreaks.com/topic/159359-solved-users-status/page/2/#findComment-846788 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.