Jump to content

'logged' in visitors list problem


dazzathedrummer

Recommended Posts

Hi,

 

I'm trying to create a page that shows information about people visiting my site, particularly whether they are logged in or not.

 

The login system works fine and i can get info on who's visiting by writing session info to a db and retrieving it - that's all ok.

 

It just doesn't work when I combine the two.

 

What i'm trying to do is detect a cookie that was set by logging in on a different page - if it's set then $member stores the username and writes that to the db with the the session data.

 

I also have a similar if statement that detects another cookie that is set simply by hitting the site - this is so I get info that can be 'Logged in' or 'not logged in' and 'new visitor' or 'returning visitor'.

 

Both of the if statements return 'false' results despite my having logged in and checked that the cookies exist - and if I echo out the variables, I get the results that I expect - my username and 'returning visitor'

I'm not understanding why the 'false' results are being posted to the db despite the fact that both if statements seem to be (and should be) returning trues.

 

here is the code that I have placed at the very top of my 'index.php': -

<?php
session_start();
$ses = session_id();
$time = time();
$timech=$time-300; 

//checks logged in cookie
if(isset($_COOKIE['guard_member']))
{
$member= $_COOKIE['guard_member'];
}
else 
{
$member= 'not logged in';
}


//checks visitor cookie
if(isset($_COOKIE['guard_visit']))
{
$visitor ='returning visitor';
}
else 
{
$visitor= 'new visitor';
}
//stores browser info
$browser= ($_SERVER['HTTP_USER_AGENT']);


mysql_connect("database", "user", "password") or die(mysql_error()); 
mysql_select_db("the_guards_org_uk_users") or die(mysql_error()); 



$result = mysql_query("SELECT * FROM tg_session WHERE session='$ses'");
$num = mysql_num_rows($result); 

if($num == "0"){
$result1 = mysql_query("INSERT INTO tg_session (session, time, username, status, browser_os)VALUES('$ses', '$time', '$member', '$visitor', '$browser')");
}else{
$result2 = mysql_query("UPDATE tg_session SET time='$time' WHERE session = '$ses'");
} 

$result3 = mysql_query("SELECT * FROM tg_session"); 

$usersonline = mysql_num_rows($result3);
//echo "There are: <b>".$usersonline."</b> users online";  
//echo $member;
//echo $visitor;

mysql_query("DELETE FROM tg_session WHERE time<$timech");
?> 

 

Just to reiterate; the cookies are set before coming to this page and the data writes to the db fine - it just seems to be the wrong data.

 

?

 

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.