DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   visitor Details (http://www.daniweb.com/forums/thread168320.html)

rajeesh_rsn Jan 14th, 2009 9:19 am
visitor Details
 
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 ????

almostbob Jan 14th, 2009 2:45 pm
Re: visitor Details
 
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

almostbob Jan 14th, 2009 2:50 pm
Re: visitor Details
 
or install the geoip library
and map the locations from the ip and crate a googlemap mashup of the ip locations

almostbob Jan 15th, 2009 1:29 am
Re: visitor Details
 
Quote:

Originally Posted by almostbob (Post 778349)
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;

rajeesh_rsn Jan 15th, 2009 10:39 am
Re: visitor Details
 
Thank you for the kind support..


All times are GMT -4. The time now is 6:31 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC