| | |
How to display online users
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
Is there anyone with the knowledge on how to Show online users with php??
i have seen in many sites,now i need someone who can explain to do it.
(if there are users who are online to be displayed)
Please explain how to get started))))
i have seen in many sites,now i need someone who can explain to do it.
(if there are users who are online to be displayed)
Please explain how to get started))))
Last edited by mrcniceguy; Sep 28th, 2008 at 2:51 pm. Reason: forgot
Well, I'm not expert with PHP, but I would suggest creating an SQL table called onlineUsers or somthing like that. Then when users login a PHP script adds them to the table. When they logout, simply remove them from the list.
Something like:
And on Logout:
Something like:
php Syntax (Toggle Plain Text)
<?php //Log the user in $con = mysql_connect("localhost","username","password"); mysql_query("INSERT INTO onlineUsers (username) VALUE ('$username')") //Assuming the user's username is stored in $username ?>
php Syntax (Toggle Plain Text)
<?php //Clear Cookies, etc. $con = mysql_connect("localhost","username","password"); mysql_query("DELETE FROM onlineUsers WHERE username = '$username'") //Assuming the user's username is stored in $username ?>
Last edited by FlashCreations; Sep 28th, 2008 at 4:01 pm. Reason: Added some code
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
when someone is login his datas are been sent to ONLINE TABLE.
THE problem comes when login Out,the query is not deleting his datas.
Check the code below,is the one i`m using for login out.It was working but after i added this DELETE is no longer.
THE problem comes when login Out,the query is not deleting his datas.
Check the code below,is the one i`m using for login out.It was working but after i added this DELETE is no longer.
PHP Syntax (Toggle Plain Text)
<?php session_start(); $user=$_SESSION['user']; if(session_is_registered('user')){ $del="DELETE FROM online WHERE user='$user'"; $true=mysql_query($del); if($true){ echo"member offline"; }else{ echo"failed to delete"; } session_unset(); session_destroy(); //include"index.php"; //exit(); }else{ include"index.php"; } ?>
Ok then, try this:
PHP Syntax (Toggle Plain Text)
<?php session_start(); if(session_is_registered('user')) { $user=$_SESSION['user']; $del="DELETE FROM online WHERE user='$user'"; $result=mysql_query($del); if($result==true) { echo "<h3>Member Offline</h3>\n"; } else { echo "<h3>Failed to Logoff</h3>\n"; } //Remove the Session Vars $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); //include"index.php"; } else { include "index.php"; } ?>
best way to store session and count how many session ............
Help as an alias
I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
The simplest way to do this would be to read the number of active sessions as nikesh.yadav said.
I have added the code I use on my sites to give an example:
I have added the code I use on my sites to give an example:
php Syntax (Toggle Plain Text)
<? $number=0; // define the directory to save sessions in session_save_path("session_directory"); session_start(); // set the session as active $_SESSION['active']="yes"; $directory = opendir("sessions"); while($item = readdir($directory)) { if(($item != ".") && ($item != "..")) { // count the number os sessions active within the last x sexonds if(fileatime('sessions/' . $item) > time()-120) { // add 1 to the session count $number++; } } } closedir($directory); session_unset(); // return the value return ($number=='1') ? "There is " . $number . " user online now." : "There are " . $number . " users online now."; ?>
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
![]() |
Similar Threads
- Diplaying Excel Spread aheets online (ASP.NET)
- find online users (Shell Scripting)
- Users management (PHP)
- Who's online (ColdFusion)
- PHP Help - Display forum online and total members on main page (PHP)
- active users scroller (JavaScript / DHTML / AJAX)
- Online voting !! (ASP.NET)
- IPB vs. phpBB (Growing an Online Community)
Other Threads in the PHP Forum
- Previous Thread: Date list
- Next Thread: dynamically built webpage for multiple audio and text points.
| Thread Tools | Search this Thread |
apache api array back basic beginner binary broken cakephp checkbox class cms code computing confirm cron curl customizableitems database date delete display dynamic echo email error external file files filter folder form forms forum function functions gc_maxlifetime google headmethod host href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php problem query question radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validator variable video web xml youtube





