User Status: Online / Offline

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Firstly:
Define what beeing online is.

If beeing online is when you have a page (without frames) open and doing nothing with the server, you have a problem.
One solution could be to write a flash or java applet and let it access something on a regular basis, and let that keep track of who does what.

If beeing online is about fetching new pages now and then, you could always register the access time of a user when he loads a page. If that timestamp is too old, he's offline.
alexus
Forum Contributor
Posts: 159
Joined: Fri Jul 04, 2003 10:49 pm

Post by alexus »

Online is when the browser window is open and link with server exist...
ik
Forum Commoner
Posts: 34
Joined: Thu Jul 10, 2003 5:33 am
Location: Lancs Uni, UK
Contact:

Post by ik »

But why don't just to write into $_SESSION[] time of last user login - and then check it? It seems to be much more secure than using of client-side applets.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

because let's say i login at 10 but keep on the site till 1700

at some point it'll say i'm offline when i'm here answering people. what they would have to do for your suggestion is "last page load" in session and look at that. but that wouldn't work. they want tohers to know when you're online
that requires a db feild to check.

personally i don't think it would be a big strain on a db, so i'm thinking of using that.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

that job belongs to DATABASE :)
alexus
Forum Contributor
Posts: 159
Joined: Fri Jul 04, 2003 10:49 pm

Post by alexus »

Enough theory please 8) (we are not at school here), I still not quit sure how to do a finale script…

I like the example that count the number of session files, but it can’t show me the “names” of the users… I tried to play with msession_list() but I didn’t get it to work…

And actually I (and probably every one else) don’t cares will it use DB or no, because we can record page load time at any time we want…

:arrow: Let assume that we will use that session example than how can I gat the username from the session files… (Certainly the session contains not only username but also things like access levels + some temp info and ip)

:?:
PS: Does anyone know how ICQ online status works (like that web based ISQ and regular Win APP)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

habitat675 wrote:I have mine run an inline frame that refreshes every 50 seconds or so and updates the user's status. then another script deletes all files older than 1 minute and displays all of the file names for the rest (which are named as user's names). It probably wouldn't be very efficient for a large site but for mine it runs quickly and works well.
I think that is the best method. Inline frames aren't like regular frames. they don't take up any horizontal or vertical web space. They are hidden from the user within the code (by making them 1px by 1px in width+height and blending in the BG of the inline with the bg of the page). This provides for a very powerful solution and a very slick solution since it's practically invisible to a user who doesn't view source. And in theory, it is the best solution.

And I would imagine it would work best with big sites, habitat.


my 2 cents.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

alexus wrote:Enough theory please 8) (we are not at school here)
Good PHP programming requires a lot of theory. As goes with most other things.

Maybe that's why this simple solution is so hard to find for you? hmmm, just a thought.

Theory = good.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

log.php

Code: Select all

<?
if (!isset($user) or !isset($pass) or empty($user) or empty($pass))
&#123;
header( "Location: index.php" );
&#125;

else
&#123;

$connect= mysql_connect("localhost","root","boot") or die("Cannot connect to the server! Please try again later.");

mysql_select_db("db_cv",$connect) or die("Cannot connect to the database! Please try again later.");

$query = mysql_query("SELECT * FROM tbl_users WHERE user='$user' AND pass='$pass'",$connect);

$row = mysql_fetch_array($query);

$num = mysql_num_rows($query);

if ($num > 0)
&#123;

session_start();
session_register("user","uname","dbname","dbpass");

$uname = $row&#1111;"name"];
$dbname = $row&#1111;"dbname"];
$dbpass = $row&#1111;"dbpass"];

header("Location: admin.php");

&#125;

else
&#123;
echo "Incorrect login name or password. Please try again.";
&#125;

mysql_close($connect);
&#125;
?>
---------------------------------------------------------------------------
ADMIN.PHP (ONLY THE PARTS WHERE YOU USE NAMES FROM SESSION)

Code: Select all

<td width=150><div align="center"><a class="arif" href="logout.php">Logout <? echo $uname; ?></a></div></td>
------------------------------------------------------------------------
SECURE.PHP

Code: Select all

<?

ob_start();

session_start();

if(!session_is_registered("user"))
&#123;
header("Location: index.php");
session_unset();
exit();
&#125;

?>
By the way, Secure.php is included in admin.php at the beginning of document.
(require("secure.php");)
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

I use the IFRAME method myself as it seems to be the best way.

The only difference is I put the IFRAME within a DIV and just set the position:absolute and the visibility:hidden in it's style... that way it is completely invisible and doesn't take up any page space at all.

Another use for this is to have the IFRAME pull information from say a 'shout box' database and then use a bit of javascript... object.innerHTML .... to update some page content on-the-fly without the user having to refresh the main page at all.

You could use the same method to update who is on-line more or less in real-time without the user having to refresh the page to find out.

And..... ( I've nearly finished )...... how about alerting the user using the same method whenever they get a new reply added to their forum topics.. or get a new note from another user!?


As the old saying goes "It's not what you've got, it's how you use it".
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I never thought about that DIV tag invisibility thing to be used for this, hmm i like it. ;)

About refreshing; using a meta-refresh in the <head> tag to refresh every 5 seconds should do the trick also.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

ummm... not everyone has iframe support.

if you really want it to be universal then you want to have it so that everyone can use ithave table "last access"
it takes two fieds, username and access time

select * from last_access where access_time <5 min ago sort by username


easy and universal
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

m3rajk wrote:ummm... not everyone has iframe support.
Well... my view on that is that all modern browsers can use IFRAMEs... if people are still using browsers old enough not to support IFRAMEs then they don't deserve to access the site. simple.

I can't stand people who can't be bothered to update their browser.. it holds back website development and the evolution of the web as a whole.

These days I develop sites for IE5+ and NS6+ only.. if you don't have either of those then you don't get access to the site.

Having to constantly downgrade sites and limit the possibilites of website development just to keep the people using old browsers happy won't last much longer because people will just get fed up of being held back.


..a bit off-topic but those couple of words really annoyed me.. sorry!
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

well.. the site i'm making, we decided that we wanted a certain set up and that it would require them.

ie is only at 6. i think 5 doesn't have full iframe support but 5.5 does. enough people still use 5...

i knoq a lot of people switched to mozilla iinstead of netscape 6.

mozilla is actually better with all that. i know because i'm one of them. and those i know that didn't switch to netscape 6 ( a small number) use 4.81, the last 4.xx that will be made according to netscape.

personally, i know that i consider what i'm making the site for with what i use. i don't een use frames if i am making a site for someone that wants it to be universally accessable. (haven't done that in ages)

at this point anyone that doesn't have the support of iframes is problaby using a web clipper or text-only (ie: lynx... yes it's still around)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I agree. I have the "If you don't bother having to the latest software, why should i adjust my code/design to suit your needs?" mentality also.

No update = No site. Plain and simple. 8)
Post Reply