Hi.
On Sep 15, 2004, at 6:55 AM, Vincent Jordan wrote:
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.
You might make sure that on the page where it says session_destroy(); that you have actually carried the session over. Meaning, if it's on a different page than you originally started the session, make sure you include session_start(); at the beginning of that next page.
Also, something you might want to try is first testing to see if the session is set.
if (session_id()) session_destroy();
That part doesn't really help your specific situation (as far as destroying the session), but I think it's good practice and will not give an error message if your session has not been started yet and you try to destroy it.
Hope this helps you some.
~Philip
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php