I needed the same thing and finally I was able to throw one together. If you've allready got a comunity
running with 10 Discussion boards, 10 chat rooms, with webmail and web sites for each of the 100 members
running against a mysql database using a cookie- md5 login system, PHP sessions is not the quikest
answer to some of these problems; but more of a longer term solution. I would definitly say that
if your building something new, then sessions should be the way to go or if you expect thousands of
members then you perhaps should do an over night switch.
In any case, I think the answer to your question can be found here, although this works for me, I'm not a scripting
guru to say the least and simply trial and error tells me that this system is working; Clean or not. Perhaps
someone else here can clean it up a bit smoother.
After constantly killing cookies on the users machine became a problem by the fact that some user
machines wouldn't properly delete a cookie that has been set to delete (tested even here on the phpbuilder system);
and since hacker security isn't the largest concern in this community; I changed the cookies expiration values
to delete in a year. Unless that user wants to loggin again as a different user. Then they are directed to a page that will delete
the cookies.
Ok, it seems as though, that has solved the cookie problem as users are able to log in again that
were having cookie problems before. I would rather switch everything over to php sessions and have compiled
a php sessions mysql session handler (from here at phpbuilder), for that purpose, I don't have time for the
switch over right this second.
So anyway,
I use a framed page system structure which allows hidden refreshing pages around the borders of the
page. Also allows the use of a colored borders.
When an individual hits the main page, they get the splash page with entry links. The left border
page has started pre-loading the "way-to-heavy" graphics. The right border starts a refresh, first
it checks to see if you have the cookie, if so, the cookie is authenticated and then the page starts
looking for that user to set the database to "onnow".
After that user gets through the "Hide me / Show me" page, the database "onnow" field is set to a positive
value. Then the right border page pics up the fact that you are now "onnow" and sets the database
to show that the "justin" field has a positive value and fires off a javascript to make the top border
start a refresh.
lol,,,
The top border waits a few seconds, (15 I think) then sets the users "justin" feild to show as "d" for Done!,,,
The top border than start a refresh to check for a new value through all users in the "justin" field. If it finds
a positive value, it fires off a javascript small popup window that flys up from the bottom (IE) showing you(the user)
that a member has entered the site and displays a link to send that member a message. Click it and the
main parent body window will display the mailer form which includes all the users information and a profile
pic. Send that message to the members imap account. Of course, if the members e-mail account is not yet active,
might not be a good Idea to show someone they can send a message when they can't. They tend to get a little nasty
when they find out that some server dude just read thier e-mail.,,,lol
The lower border shows how many members are in-house or in-discussion or in-chat and tells the user
if they have any new e-mail. If the user clicks the log-out link, they are sent to a page that sets the database
"onnow" field back to "n" as well as all the chat rooms and the hidden mode option.
If they hit the "x" button to close the browser, a javascript is fired that opens a window and a logout
script is executed. In IE this happens at 1400 pixels from the top of the screen, which is pretty much
out of site. In Netscape, it happens in plain view but closes so fast, they only see a flash.,,,lol
OK,,,now the fun,,,,
If that user looses connection or otherwise doesn't get properly logged out; either the pop-up can get
stuck or the user is always viewed as "OnNow".
So, to create something that automatically checks for and refreshes log-ins without actually
logging out the person who is not a ghost, I set the footer border to set "onnow" as y each time
it refreshes to check the members e-mail. That means when the script logges everyone out, the
page refresh will logg'em back in if they're not ghosts.
If knowone is in the site, then ther isn't much a need to check for these glitches. So, we wait
until another user arrives and when he does and after he gets to the main homepage, the footer border
will first set him as "onnow" and set all the chat rooms to a negative.That will also place the
timestamp in the tstamp fieled.
The next block of script then grabs his timestamp, sets it as a global and holds it as $mytimestamp
Then it checks for any positive "onnow" values as well as "justin"(thePopups) values. If it finds positive
values, it compares the time stamps. If the alloted time has been surpassed, it logs all fields to "History_see_ya_bye!"
Getting all this timed is is a bit of a pain in the "A",,,,,
PHP4, Unix with MySQL,,,I'm sure someone who know what thier doen can scrunch this
together somehow.
<?
$sql="UPDATE members SET onnow='y' WHERE user_name='$user_name'";
$result=db_query($sql);
$sql = "SELECT * FROM members WHERE user_name='" . user_getname() . "'";
$result=db_query($sql);
$num = db_numrows($result);
while($myrow = db_fetch_array($result))
{
global $mytimestamp;
$mytimestamp = $myrow["tstamp"];
}
$sql = "SELECT * FROM members WHERE onnow='y'";
$result=db_query($sql);
if ($result || db_numrows($result) > 0){
$num = db_numrows($result);
while($myrow = db_fetch_array($result))
{
$user_id = $myrow["user_id"];
$timestamp = $myrow["tstamp"];
$justin = $myrow["justin"];
if ($timestamp <= $mytimestamp -1038) {
$sql="UPDATE members SET onnow='n' WHERE user_id='$user_id'";
$result=db_query($sql);
}
}
}
$sql = "SELECT * FROM members WHERE justin='y'";
$result=db_query($sql);
if ($result || db_numrows($result) > 0){
$num = db_numrows($result);
while($myrow = db_fetch_array($result))
{
$user_id = $myrow["user_id"];
$timestamp = $myrow["tstamp"];
$justin = $myrow["justin"];
if ($timestamp <= $mytimestamp -15) {
$sql="UPDATE members SET justin='n' WHERE user_id='$user_id'";
$result=db_query($sql);
}
}
}
?>