Jump to content

[SOLVED] little help with this user online code


irkevin

Recommended Posts

Hi everyone, someone mind tell me if there are some changes i need to make with this code?

 

<?php
include('config.php');
include('functions.php');
mysql_connect($server, $dbusername, $dbpassword);
mysql_select_db("$user_online");

$uname = $_SESSION['user_name'];
if (!$uname)
{ 
$guest = "1"; 
} 
else
{ 
$guest = "0"; 
}
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();
$query = "SELECT * FROM user_online WHERE ip = '$ip'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 1)
{
      $query2 = "UPDATE user_online SET uname='$uname',time='$time',guest='$guest' WHERE ip = '$ip'";
      $result2 = mysql_query($query2);
}
else
{
      $query2 = "INSERT INTO user_online (uname,ip,time,guest)VALUES('$uname', '$ip', '$time','$guest')";
      $result2 = mysql_query($query2);
}

$time3 = time() - 300;
$query3 = "DELETE FROM user_online WHERE time < $time3";
$result3 = mysql_query($query3);
$query4 = "SELECT * FROM user_online WHERE guest = '1'";
$result4 = mysql_query($query4);
$guestonline = mysql_num_rows($result4);
$query5 = "SELECT * FROM user_online WHERE guest = '0'";
$result5 = mysql_query($query5);
$memonline = mysql_num_rows($result5);
$totalonline = $guestonline + $memonline;
echo 
"Guests: $guestonline<br />
Members: $memonline<br />
Total: $totalonline<br /><br />";
?>

 

sometimes, it shows only one user online even if there are more than one user logged in in my site

 

Link to comment
Share on other sites

Hi again with a little problem with this code, it actually shows the user who is online but it removes it after a short period of time even if the user is still logged in..

 

What should i modify in this code in order that it removes the user only when he logs out?

 

Can someone help me with this?

 

Thanks  :D

Link to comment
Share on other sites

Sorry to bug you with this again

 

for the logged users, the code works but supposed a guest is looking at the website, basically it will add him as a guest but how do I removed the guest from the database once he close the browser and dont watch the website again.. Is there a way i can do that?

 

Thanks for all your help btw

Link to comment
Share on other sites

<?php
function session_restart()
{
    if (session_name()=='') {
        // Session not started yet
        session_start();
    }
    else {
        // Session was started, so destroy
        session_destroy();
}
}
if($_SESSION['user_name']=="guest"||"javascript:window.close()") 
{ $query="DELETE*FROM user_name WHERE guest=0";
session_restart($_SESSION['user_name']);}



?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.