hi I had a web site made in php. I need to collect visitor data ( ip address, visiting time) and store in it a database. I wrote the code like this

date_default_timezone_set('Asia/Calcutta');
$time= date('D,F j, Y, H:i:s A');
$ip=getenv("REMOTE_ADDR");
mysql_query("INSERT into visitordetails (ip,time) VALUES ('$ip','$time')") or die(mysql_error());

and this is works perfectly for me.. Let me know am i need to do anything more in it ????

Dont format the date until you pull the data out of the database
its much quicker to update the table or perform compares when later reporting if the data is timestamp

and

<?php
$timestamp = time();
$timeout = $timestamp - 1500;
//Insert User
$insert = mysql_query("INSERT INTO TG_whos_online (timestamp, ip, file) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."')") or die("Error in who's online insert query!");
//Delete Users
$delete = mysql_query("DELETE FROM TG_whos_online WHERE timestamp<$timeout") or die("Error in who's online delete query!");
//Fetch Users Online
$result = mysql_query("SELECT DISTINCT ip FROM TG_whos_online") or die("Error in who's online result query!");
$users = mysql_num_rows($result);
//Show Who's Online
if($users == 1) {
print("<span>$users Person Online. &nbsp;</span>\n");
} else {
print("<span>$users People Online. &nbsp;</span>\n");
}
?>
/*
This is the database creation SQL. You will need to create this table in your MySQL database.
*/ 
 
 CREATE TABLE `TG_whos_online` (
  `id` bigint(20) NOT NULL auto_increment,
  `timestamp` int(15) NOT NULL default '0',
  `ip` varchar(40) NOT NULL default '',
  `file` varchar(100) NOT NULL default '',
  PRIMARY KEY  (`id`),
  KEY `ip` (`ip`),
  KEY `file` (`file`),
  KEY `timestamp` (`timestamp`)
) TYPE=MyISAM;

add a visitcount column to the database

$query = mysql_query(sprintf("select id from visitordetails where ip='%s';", $_SERVER["REMOTE_ADDR"]));
	list($id) = mysql_fetch_row($query);
	if (strlen($id)) 
		{
		if (!mysql_query(sprintf("UPDATE visitordetails SET visitcount = visitcount + 1 WHERE ip ='%s';", $_SERVER["REMOTE_ADDR"])));
		{	
		return false;
		}
		return true; 
		}

and/or update the table with a last_visit column and do the same exist check to post the current timestamp to last_visit

or install the geoip library
and map the locations from the ip and crate a googlemap mashup of the ip locations

and/or update the table with a last_visit column and do the same exist check to post the current timestamp to last_visit

query = mysql_query(sprintf("select id from visitordetails where ip='%s';", $_SERVER["REMOTE_ADDR"])); 
list($id) = mysql_fetch_row($query); 
if (strlen($id))  { 
if (!mysql_query(sprintf("UPDATE visitordetails SET visitcount = visitcount + 1, lastvisit='%s' WHERE ip ='%s';" ,$timestamp, $_SERVER["REMOTE_ADDR"])));
{ return false; } 
return true;
This question has already been answered. Start a new discussion instead.