| | |
visitor Details
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved
![]() |
•
•
Join Date: Sep 2008
Posts: 132
Reputation:
Solved Threads: 0
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
and this is works perfectly for me.. Let me know am i need to do anything more in it ????
PHP Syntax (Toggle Plain Text)
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
add a visitcount column to the database
and/or update the table with a last_visit column and do the same exist check to post the current timestamp to last_visit
its much quicker to update the table or perform compares when later reporting if the data is timestamp
and
php Syntax (Toggle Plain Text)
<?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. </span>\n"); } else { print("<span>$users People Online. </span>\n"); } ?>
sql Syntax (Toggle Plain Text)
/* 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
php Syntax (Toggle Plain Text)
$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; }
Failure is not an option It's included free
If at first you dont succeed, join the club
Please mark solved problems, solved
If at first you dont succeed, join the club
Please mark solved problems, solved
•
•
•
•
and/or update the table with a last_visit column and do the same exist check to post the current timestamp to last_visit
php Syntax (Toggle Plain Text)
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;
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
If at first you dont succeed, join the club
Please mark solved problems, solved
![]() |
Similar Threads
- [For Hire] Installation Software and Templates (Post your Resume)
- PR5 Java Tutorials Site freejavaguide.com (Websites for Sale)
- Arcade Ship – over 2,000 games, unique design, making $250/month (Websites for Sale)
- Complete noob needs lots of help (Networking Hardware Configuration)
- How many visitors on average? (Promotion and Marketing Plans)
- Submit Button Help (JavaScript / DHTML / AJAX)
- My forum is not growing -- and I'm tired and drained literally (Website Reviews)
- a few search engine optimization questions (Search Engine Optimization)
Other Threads in the PHP Forum
- Previous Thread: How to add amount of items in shopping cart? Need urgent help!
- Next Thread: please tell me what is wrong with the code
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic echo email error file files filter folder form forms forum function functions gc_maxlifetime global google headmethod href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php phpmysql query question random recourse recursion regex script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube






