Using sessions to gather visitor information

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am trying to track the users that visit one page on a site. I am having a
couple of problems. The time seems to be 5 hours off. I do not have any
tables as of yet what I would like to do is only count an ip address as one
in a 24 hour period, if more than one visit then update visit count.I have
played around with the time using date() and localtime().  Here is what I
have sofar.

 

ini_set('display_errors',1);

error_reporting(E_ALL & ~E_NOTICE);

session_start();

$_SESSION['ip_address'] = $IP;

$_SESSION['user_agent'] = $Browser;

$_SESSION['host_name'] = $Host;

$_SESSION['visit_time'] = $now;

 

$now = localtime();

$now = $now[2] . ":" . $now[1] . ":" . $now[0];

$IP = getenv(REMOTE_ADDR);

$Browser = $_SERVER['HTTP_USER_AGENT'];

$Host = getHostByName($IP);

 

I have not setup tables yet but I think I will use this:

vid init(5) not null auto_incriment

ip varchar(25) null

agent varchar(100) null

host varchar(100) null

time varchar(10) nul

visitcount int(100) null

 

when a visitor loads the page I can run this

 

mysql_query(SELECT ip, time FROM tablename where ip=$_SESSION['ip_address']
and time=$_SESSION['visit_time'])

 

I would like to query if $_SESSION['ip_address'] has visited in less then 24
hours then kill session and close mysql connection. If last visit was more
than 24 hours update time and add +1 to visitcount. If new visit add to
table. 

 

Once all done how can I properly clean up the session. I have tried the
following bur get an error

unset($_SESSION);

session_destroy();

I tried this with a link to another page and got this error:

Warning: session_destroy(): Trying to destroy uninitialized session in
/home/content/html/killtest.php on line 5

I assume I forgot something. 

 

Any help would be appreciated. 

 

 

 


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux