| | |
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: 142
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, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
or install the geoip library
and map the locations from the ip and crate a googlemap mashup of the ip locations
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, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
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, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
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
Views: 659 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update updates upload url validation validator variable video web xml youtube






