RE: [SPAM] Re: [PHP-DB] Using sessions to gather visitor information

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

 



John and everyone else, thanks for all the help. Here is what I have for
code. Again you help is greatly appreciated. 




<?php
ini_set('display_errors',1);
error_reporting(E_ALL & ~E_NOTICE);
ini_set('register_globals',0);

session_start();
// Set var
$now = date('g:i');
$IP = getenv(REMOTE_ADDR);
$Browser = $_SERVER['HTTP_USER_AGENT'];
$Host = getHostByName($IP);
// define sessions
$_SESSION['ip_address'] = $IP;
$_SESSION['user_agent'] = $Browser;
$_SESSION['host_name'] = $Host;
$_SESSION['visit_time'] = $now;
// print for debug
if (session_id()) {
echo $_SESSION['ip_address'] . "<br />";
echo $_SESSION['user_agent'] . "<br />";
echo $_SESSION['host_name'] . "<br />";
echo $_SESSION['visit_time'] . "<br />";
}

// look for db entry
$IpSearch = mysql_query("SELECT ip, time FROM visitor where ip =
{$_SESSION['ip_address']}");
$Results = mysql_fetch_row($IpSearch);
if($Results) {
// need to figure out how to check if time greater than 24 hours from now
// if greater than 24 hours do:
$UpdateVisit = mysql_query("UPDATE visitor SET time =
'$_SESSION['visit_time']', visitcount = /* add +1 */ WHERE ip =
$_SESSION['ip_address']");
} else {
$InsertVisit = mysql_query("INSERT INTO visitor (ip, agent, host, time,
visitcount) VALUES ($_SESSION['ip_address'], $_SESSION['user_agent'],
$_SESSION['host_name'], $_SESSION['visit_time'], '1' ");


?>

-- 
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