View Full Version : sessions and cookies???

03-31-2003, 12:51 PM
hiya guys could someone please explain the whole sessoin thing or a good tutorial that would alow me to use a session with a cookie??i dont get sessions lol and my site is all cookieenabled but i wuld like to show online/offline status.. unless there is someway of doing ths with cookies...

04-01-2003, 12:24 AM
If you use MySQL for your users, you could just do this:

function updateLogin($userId) {
mysql_query('update Users set lastLoginTime = NOW() where userId = "' . $userId . '"');

function isOnline($userId, $onlineTime = 30) {
$result = mysql_query('select * from Users where userId = "' . $userId . '" and lastLoginTime > NOW() - interval ' . $onlineTime . ' second');
$object = mysql_fetch_object($result);
return (($object->userId) ? true : false);

This is kinda what I use, $userId is the id of the user (I assume your users have some sort of ID, it basically points to the unique ID each user should be given in any coherent user database) and $onlineTime is the time in seconds the query should check for, in this example, calling isOnline(3) would return true if the user whose userId = 3 has accessed the page in the past 30 seconds (and run the updateLogin($userId) function).

04-02-2003, 02:50 AM
hey thank you man lots could i just ask tou what the -> does ive seen it in several places just ive never used it or learned it really doesnt it compare two things??

04-02-2003, 11:27 AM
It calls functions from within a class.

class $foo {
function boo() {
i = 10;
return i;

Then it is called using the arrow operator



04-03-2003, 07:58 PM
That example you gave, kapil, you set an interval.

I didn't quite get what you meant. Please could you explain it a bit more. How could you use it for a whos online thing?