Re: Using sessions to gather visitor information

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

 



From: "Vincent Jordan" <vjordan@xxxxxxxxxxxxxxx>
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);

How about showing some actual code and giving details on what doesn't work? This code doesn't make sense, as you're calculating $now, $IP, etc after you've assigned them to the session...


Basic debugging steps: start printing out variables and ensuring they have a value and it's what you think it should be. Print out your queries before you execute them to look for obvious errors. Turn register_globals OFF.

I have not setup tables yet but I think I will use this:
[snip]
time varchar(10) nul

This should be a DATETIME or TIMESTAMP field.

[snip]
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

$_SESSION = array();

will clear the session. If you unset() it, I don't think it's written at the end of the script, so your data remains. session_destroy() then probably fails because $_SESSION is gone or you never called session_start() on the page.

---John Holmes...

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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

  Powered by Linux