| | |
People online in a site using php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 140
Reputation:
Solved Threads: 0
Hai I am developing a community website and peoples can create their profile and can add friends and all. But I need to show a notification if that visitor is online . Or show all visitors in online in a page. I use mysql database.
I make it like this way :- There is a column in database with status. When an user login then it will updated to "online" and when they logout it will goes to "offline". Works fine but If an user close their browser window then it will show that user is online.
Please anyone give an idea.
Thanks
Rajeesh
I make it like this way :- There is a column in database with status. When an user login then it will updated to "online" and when they logout it will goes to "offline". Works fine but If an user close their browser window then it will show that user is online.
Please anyone give an idea.
Thanks
Rajeesh
•
•
Join Date: Sep 2008
Posts: 140
Reputation:
Solved Threads: 0
Thanks for your support. If you dont mind please give me some more clue... How to do it with Session variables ? Thanks
alright you need to change you status to the following you need to make it a time stamp that will hold the last action of user not have status hold "Online" or "Offline" ok and then you need to make a background script the will input the last action in the users status column then go to your get_online.php or what ever the name of the get users Online script is named in you directory and add to the following below
you need to make a function that will get users last action that will will go through another function that will decide if the user has been inactive of how ever long you pick like time()+3600 which is an hour in seconds and if the user had been in active for that long it will tell everyone the user is offline if not it will tell every one that the user is online alright see i am doing the same thing right now for myself i just have an understanding about how it should be done but i haven't wrought the script yet myself if you follow these instructions you can get it done with what you need and hey whats you site's url so i can keep it in mind for future when you site is finished
Sorry this is not the script
for the online offline
my
$lastaction = mysql_query("SELECT status FROM users WHERE id = $friendid");
if($lastaction >= time()-3600) {
echo "Offline";// or echo nothing
}elseif ($lastaction < time()-3600) {
echo "Online";// or echo you Online image
}
hope you get the idea Sorry for not much script but once i have it done and you still don't i'll pass it on to you alright this is just the concept ok
you need to make a function that will get users last action that will will go through another function that will decide if the user has been inactive of how ever long you pick like time()+3600 which is an hour in seconds and if the user had been in active for that long it will tell everyone the user is offline if not it will tell every one that the user is online alright see i am doing the same thing right now for myself i just have an understanding about how it should be done but i haven't wrought the script yet myself if you follow these instructions you can get it done with what you need and hey whats you site's url so i can keep it in mind for future when you site is finished
Sorry this is not the script
for the online offline
my
$lastaction = mysql_query("SELECT status FROM users WHERE id = $friendid");
if($lastaction >= time()-3600) {
echo "Offline";// or echo nothing
}elseif ($lastaction < time()-3600) {
echo "Online";// or echo you Online image
}
hope you get the idea Sorry for not much script but once i have it done and you still don't i'll pass it on to you alright this is just the concept ok
Last edited by jcanaway; Apr 22nd, 2009 at 8:42 am.
Canaway Productions
alright i been going over some scripts and I've wrought this script call getOnlineUser.php OK go to you Mysql the go to you members table the add field to the table called lastvisit and lastvisit will be a varchar there is no default and finish the field then come back to this script and add your db_connect.php to the page then edit to you standards then continue and check and see if it works it so let me know if it dose i would like to know and if not let me know and ill go over it and help you out some more by fixing any mistakes I've if i did PHP Syntax (Toggle Plain Text)
<?php include('db_connect.php'); $uid = $_COOKIE['userid']; // this is the users id Variable $fid = $_SESSION['friends_id'];// this is the friends id Variable $passkey = $_COOKIE['passkey']; // this is not the password it is in place of the password and it is an auto randomized ever time you login and logout to stop people from hacking $time = time(); // this is a Unix time stamp $timeframe = '900'; // 900secs = 15mins || this is how long till the user is shown to be offline of in case the user exits out of browser or have logged or has user IDLE's to long but is cookie dose not time out all they have to do is refresh the page and the will be shown online again $lastaction = msql_query("SELECT lastvisit FROM users WHERE id = $friendid AND passkey = $passkey"); // this lastvisit from users table where the id = user id if ($lastaction <= $time) { $online_offline = print "<img class=\"online\" src=\"images/online_offline/offline_1.gif\">";// this will show that your user is currently offline }elseif ($lastaction > $time){ $online_offline = print "<img class=\"online\" src=\"images/online_offline/online_1.gif\">";// this will show that your user is currently online } function update_lastaction(){ $uid = $_COOKIE['userid']; $time = time(); $timeframe = '900'; // 900secs = 15mins; 1800secs = 30mins; 3600secs = 1hour; msql_query("UPDATE users SET lastvisit = ".$time+$timeframe." WHERE id = $uid"); }// this function gets inputted into each page.php or init.php page what you put in each page.php is below // update_lastaction(); //now if you wont to show online/offline add in the Variable below to your profile html and every other html page you want // $online_offline; ?>
Last edited by jcanaway; Apr 22nd, 2009 at 5:56 pm.
Canaway Productions
•
•
Join Date: Oct 2008
Posts: 69
Reputation:
Solved Threads: 0
you can check out this script. it's a great jump off point. http://www.evolt.org/PHP-Login-Syste...Admin-Features
![]() |
Similar Threads
- php.ini confusion (PHP)
- Do "Regulars" Hang Out On "Who's Online"? (DaniWeb Community Feedback)
- Opinions? javascript/php/etc and programming standards (JavaScript / DHTML / AJAX)
- do u advice me to do my online store using ASP or PHP (IT Professionals' Lounge)
- Freelance PHP/MySQL Developer available (Post your Resume)
- PHP coder needed for online game (Web Development Job Offers)
Other Threads in the PHP Forum
- Previous Thread: Print the content from gridview on php page
- Next Thread: URL Rewrite in PHP
| Thread Tools | Search this Thread |
.htaccess ajax apache api array arrays beginner binary broken cakephp checkbox class cms code confirm cron curl customizableitems database date directory display download dynamic echo email error external file files folder form forms forum function functions google headmethod href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail malfunction menu mlm mod_rewrite multiple mysql neutrality oop paypal pdf php play problem query question radio random recursion regex remote root script search select server sessions sms soap source space sql syntax system table tutorial update upload url validation validator variable video web xml youtube





