visitor Details

Thread Solved
Reply

Join Date: Sep 2008
Posts: 132
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

visitor Details

 
0
  #1
Jan 14th, 2009
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

  1. date_default_timezone_set('Asia/Calcutta');
  2. $time= date('D,F j, Y, H:i:s A');
  3. $ip=getenv("REMOTE_ADDR");
  4. 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 ????
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,268
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 160
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: visitor Details

 
0
  #2
Jan 14th, 2009
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
  1. <?php
  2. $timestamp = time();
  3. $timeout = $timestamp - 1500;
  4. //Insert User
  5. $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!");
  6. //Delete Users
  7. $delete = mysql_query("DELETE FROM TG_whos_online WHERE timestamp<$timeout") or die("Error in who's online delete query!");
  8. //Fetch Users Online
  9. $result = mysql_query("SELECT DISTINCT ip FROM TG_whos_online") or die("Error in who's online result query!");
  10. $users = mysql_num_rows($result);
  11. //Show Who's Online
  12. if($users == 1) {
  13. print("<span>$users Person Online. &nbsp;</span>\n");
  14. } else {
  15. print("<span>$users People Online. &nbsp;</span>\n");
  16. }
  17. ?>
  1. /*
  2. This is the database creation SQL. You will need to create this table in your MySQL database.
  3. */
  4.  
  5. CREATE TABLE `TG_whos_online` (
  6. `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
  7. `TIMESTAMP` INT(15) NOT NULL DEFAULT '0',
  8. `ip` VARCHAR(40) NOT NULL DEFAULT '',
  9. `file` VARCHAR(100) NOT NULL DEFAULT '',
  10. PRIMARY KEY (`id`),
  11. KEY `ip` (`ip`),
  12. KEY `file` (`file`),
  13. KEY `TIMESTAMP` (`TIMESTAMP`)
  14. ) TYPE=MyISAM;

add a visitcount column to the database
  1. $query = mysql_query(sprintf("select id from visitordetails where ip='%s';", $_SERVER["REMOTE_ADDR"]));
  2. list($id) = mysql_fetch_row($query);
  3. if (strlen($id))
  4. {
  5. if (!mysql_query(sprintf("UPDATE visitordetails SET visitcount = visitcount + 1 WHERE ip ='%s';", $_SERVER["REMOTE_ADDR"])));
  6. {
  7. return false;
  8. }
  9. return true;
  10. }
and/or update the table with a last_visit column and do the same exist check to post the current timestamp to last_visit
Failure is not an option It's included free
If at first you dont succeed, join the club
Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,268
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 160
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: visitor Details

 
0
  #3
Jan 14th, 2009
or install the geoip library
and map the locations from the ip and crate a googlemap mashup of the ip locations
Failure is not an option It's included free
If at first you dont succeed, join the club
Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,268
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 160
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: visitor Details

 
0
  #4
Jan 15th, 2009
Originally Posted by almostbob View Post
and/or update the table with a last_visit column and do the same exist check to post the current timestamp to last_visit
  1. query = mysql_query(sprintf("select id from visitordetails where ip='%s';", $_SERVER["REMOTE_ADDR"]));
  2. list($id) = mysql_fetch_row($query);
  3. if (strlen($id)) {
  4. if (!mysql_query(sprintf("UPDATE visitordetails SET visitcount = visitcount + 1, lastvisit='%s' WHERE ip ='%s';" ,$timestamp, $_SERVER["REMOTE_ADDR"])));
  5. { return false; }
  6. return true;
Last edited by peter_budo; Jan 17th, 2009 at 6:05 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Failure is not an option It's included free
If at first you dont succeed, join the club
Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 132
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

Re: visitor Details

 
0
  #5
Jan 15th, 2009
Thank you for the kind support..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC