473,735 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Track user's Online Status

Hello everybody,

I am developing a community site and almost all works are competed.
There is major issue that I am facing is how to track user's online
status. I am using session data to save user's login status. There are
2 major issues which I need to handle for tracking user's Online
status.

1. When login user close his/her browser.
2. When session time out.

Both of above case I need to update a field in database which holds
user's online status. I am really stuck on this.

Please help me.

Any help or suggestion are welcome.

With Regards,
Mitul Patel.

Feb 16 '07 #1
10 9402
Mitul wrote:
Hello everybody,

I am developing a community site and almost all works are competed.
There is major issue that I am facing is how to track user's online
status. I am using session data to save user's login status. There are
2 major issues which I need to handle for tracking user's Online
status.

1. When login user close his/her browser.
2. When session time out.

Both of above case I need to update a field in database which holds
user's online status. I am really stuck on this.

Please help me.

Any help or suggestion are welcome.

With Regards,
Mitul Patel.
Hi Mitul,

Enter the great adventure of Database based sessionstorage.
It is the best way I know of.

Instead of PHP's default sessionstorage (serialized sessions in files), you
can also store them in a DB.

If you are interested, start here:
http://nl2.php.net/manual/en/functio...ve-handler.php
Add some housekeeping to it when you build it (look at garbage collection
routines). It is all very straightforward once you have a database that
holds the sessions.

But don't expect that PHP automagically knows when a user closes the window.
No event is send to PHP when that happens, so you are stuck with your
default session time-out to know if a user is online.
Regards,
Erwin Moller
Feb 16 '07 #2
Thanks Erwin,

Actually I have saved session ID in database. But Actually I am facing
problem with session expire on Browser close. I have tried a things
that I am accessing session file store at session store path. If its
there then we conclude that user is still there and if its not there
then we can say that user's session is expire and user is no longer
exist. But there is a problem that this is malfunctioning some time.

Please suggest me.

Regards,
Mitul Patel.

Feb 16 '07 #3
Mitul wrote:
Thanks Erwin,

Actually I have saved session ID in database. But Actually I am facing
problem with session expire on Browser close. I have tried a things
that I am accessing session file store at session store path. If its
there then we conclude that user is still there and if its not there
then we can say that user's session is expire and user is no longer
exist. But there is a problem that this is malfunctioning some time.

Please suggest me.
Hi Mitul,

Have a look at your php.ini.
Find the part about SESSIONS.
Look at the garbagecollecti on logic/settings.

The fact that you find a sessionfile deos NOT mean that session is still
valid.
I think PHP will (out of the box) only delete old sessionfiles if the
randomnumber generator produces a number smaller than 0.01.
Thus one in a hundred times.

Here is mine (from an old php.ini)
; Percentual probability that the 'garbage collection' process is started
; on every session initialization.
session.gc_prob ability = 1

If memory serves me well newer versions of PHP have 2 numbers for this, that
are divided.
Better check carefully by yourself what your php.ini says.

Anyway, to make your directoryscan through the sessionstorage more reliable,
you might want to increase this chance to 100%, forcing stale sessions to
be removed every time anybody uses a session. This will of course slow your
application down a little if you have many sessions for PHP to scan each
time, so you better think this through, or better test. :-)

Or you write your own sessionstorageh andlers and use a database for
sessionstorage. I would advise that, but it is more work if you never did
that before. Database based sessionstorage is very fast, AND makes it
really easy for you to see who is online.

Regards,
Erwin Moller

>
Regards,
Mitul Patel.
Feb 16 '07 #4

Thanks Erwin,

Can you help me more and suggest some good idea? So I can figure out
things fast.....

Hope that you will help me...

Regards,
Mitul Patel.

Feb 16 '07 #5
Mitul wrote:
>
Thanks Erwin,

Can you help me more and suggest some good idea? So I can figure out
things fast.....

Hope that you will help me...
Well, when I first faced the situation in PHP you are in now (how to check
who is online), I found after a litlle studying that database-storage of
sessions is a good approach.

If you want to do that to, you must do the following:
1) Read up at www.php.net on sessions, mainly the part about own
sessionhandlers .
2) Google a little, at ZEND they have a few examples with code ready-to-go.
(I must warn you that the ZEND code is NOT perfect. It doesn't adres
simultanious requests to the same session as I should). But this code will
surely show you HOW things are handled.

3) Pay attention to the straightforward sessiontable.
It will roughly look like this:

CREATE TABLE tblsession(
sessionid TEXT PRIMARY KEY,
lastaccesdate datetime NOT NULL,
userid INTEGER,
sessiondata TEXT
)

Where:
- sessionid holds an unique value for each session your application creates.
This can simply be the PHP generated PHPSESSID.
- lastaccessdate is a field you update each time you use that session.
- userid is something I added for ease of lookup if a user is online.
(It contains a userid that I don't explain any futher, but you can think up
something that makes sense in your case.)
- sessiondata is the field that actually contains the sessiondata. PHP
delivers the content of this field to you, so you don't have to do the
encoding yourself.

Good luck.

One warning: I saw a lot of bad code on the net regarding databasestorage of
sessions.
Most people tend to forget that the PHPSESSID is dangerous to use straight
in the queries because it comes from a cookie (or URL), and thus from the
client, and thus could not be trusted (SQL-injection).
You'll have to sanitize the PHPSESSID everywhere you use it (and that is
almost everywhere in databasestorage queries for sessions.)

Just call addslashes() if needed. (Or mysql_real_esca pe(), or whatever suits
your SQL-injection defense strategy.) Even in O'Reilly books I saw that
mistake, and at ZEND too. It seems everybody is collectively forgetting to
sanitize the PHPSESSIONID. :-(

Regards,
Erwin Moller
>
Regards,
Mitul Patel.
Feb 18 '07 #6
Thanks a lot Erwin.

I am implementing things as per you suggestion. I will know you if I
have any problem or I got any success.

Thx,
Mitul Patel.

On Feb 18, 4:50 pm, Erwin Moller
<since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
Mitul wrote:
Thanks Erwin,
Can you help me more and suggest some good idea? So I can figure out
things fast.....
Hope that you will help me...

Well, when I first faced the situation in PHP you are in now (how to check
who is online), I found after a litlle studying that database-storage of
sessions is a good approach.

If you want to do that to, you must do the following:
1) Read up atwww.php.neton sessions, mainly the part about own
sessionhandlers .
2) Google a little, at ZEND they have a few examples with code ready-to-go.
(I must warn you that the ZEND code is NOT perfect. It doesn't adres
simultanious requests to the same session as I should). But this code will
surely show you HOW things are handled.

3) Pay attention to the straightforward sessiontable.
It will roughly look like this:

CREATE TABLE tblsession(
sessionid TEXT PRIMARY KEY,
lastaccesdate datetime NOT NULL,
userid INTEGER,
sessiondata TEXT
)

Where:
- sessionid holds an unique value for each session your application creates.
This can simply be the PHP generated PHPSESSID.
- lastaccessdate is a field you update each time you use that session.
- userid is something I added for ease of lookup if a user is online.
(It contains a userid that I don't explain any futher, but you can think up
something that makes sense in your case.)
- sessiondata is the field that actually contains the sessiondata. PHP
delivers the content of this field to you, so you don't have to do the
encoding yourself.

Good luck.

One warning: I saw a lot of bad code on the net regarding databasestorage of
sessions.
Most people tend to forget that the PHPSESSID is dangerous to use straight
in the queries because it comes from a cookie (or URL), and thus from the
client, and thus could not be trusted (SQL-injection).
You'll have to sanitize the PHPSESSID everywhere you use it (and that is
almost everywhere in databasestorage queries for sessions.)

Just call addslashes() if needed. (Or mysql_real_esca pe(), or whatever suits
your SQL-injection defense strategy.) Even in O'Reilly books I saw that
mistake, and at ZEND too. It seems everybody is collectively forgetting to
sanitize the PHPSESSIONID. :-(

Regards,
Erwin Moller
Regards,
Mitul Patel.

Feb 19 '07 #7
Hello Erwin,

I am facing following problem. Plz suggest me what to do????

Warning: session_set_sav e_handler() [function.sessio n-set-save-
handler]: Argument 1 is not a valid callback in /mnt/www/mitul/
global.php on line 31

It is not calling required functions.

Please suggest me......

Can you give me your mail id ..... Mine is mitulmpatel at gmail dot
com.

Feb 19 '07 #8
sorry wrong id give here is correct on patel.mitul.m at gmail dot
com.
Feb 19 '07 #9
Mitul wrote:
sorry wrong id give here is correct on patel.mitul.m at gmail dot
com.
Sorry Mitul,

I don't start personal emailsessions.
The idea of usenet is that everybody can read it, and if others face similar
problems, they can look up suggestions made in past.

I often found solutions for technical problems by searching googlenews
archives (The old dejanews).

So if you have a problem with your sessionhandler, please post the code in
here, and wait if anybody can help you.

Good luck!

Regards,
Erwin Moller
Feb 20 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2085
by: | last post by:
(subject included - apologies) <jason@catamaranco.com> wrote in message news:... > Is there a simple way to track users leaving our site to vendors whose wares > we have advertised as a banner on our site.....? > > Some of the vendors we deal with may not have sophisticated tracking devices > to allow us to determine if we are contributing to their sales....
1
2846
by: JLuppens | last post by:
Does anyone know if there is a way to track changes in a text field like word does? I am using a SQL2000 database and can use either VB.Net or Access. The field is either ntext or Varchar. I would like to show users the changes other users have made to a text field using a other font or font color. Thanks
2
3091
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing this by aggregating new content from all databases into a single indexed database and then saving a timestamp in the account database (for the current user) that tells me when the user last read items in the aggregated database.
8
2492
by: Dica | last post by:
i've got a client that wants to be able to review records about IIS generated emails. in his own words, he wants the "ability to track and report message status (i.e. how many messages were sent successfully, how many were blocked, how many bounced back with an incorrect address)" i'd start by adding a new row containing the email address, dateTime, etc when first sending the email, but how to track the rest of the info? for...
3
3130
by: Vincent Ye | last post by:
Hi All, I have an application which is using memship and profile functions. It works well in my develop machine which is using SQL Express Edition Server as the provider. When I move this application to the hosting server. It works well when the user is anonymous. But after user logins, the Profile_MigrateAnonymous event in Global.asax is called when user browses every pages. So even I change the value in Profile, it keeps getting...
22
2730
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other things. So, in instances where I list, for example, the latest weblogs. I list the headline of the weblog, the date and the name of the member who wrote it. Now, the name isn't just "Smith", but rather Smith's online status, his nick and his...
10
3643
by: Php Developer | last post by:
I want to know how to check that user is online or offline status if he close his browser with the help of <body onunload>.As it not work well if is user change his page as that time it is too fired.I want only to fire function if user closed browser.
3
1359
by: Ken Fine | last post by:
Hi, I'm using the VS.NET 2008 website copy tool. It is supposed to keep track of whether files are new, changed, or unchanged relative to a site on my "remote" server. Most of the time it does not maintain that information between sessions and the local and remote window indicates a "?" for the state of each file. Can anyone speculate why this behavior happens? It definitely makes the tool less easy to use. Off-topic, but I wish...
3
4038
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I want to limit the user only login the system one time at the same time. I don't want him login the system two with the same user at the same time. How to do this? If i have a table to record if this user has logined, this user didn't logout and just close IE, how do i set his recoed in the table logout? Thanks, -Billy
0
8964
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8202
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6049
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4564
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2740
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2190
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.