Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 08-06-2004, 02:16 PM   #1 (permalink)
bearslife
Registered User
 
Join Date: May 2004
Location: Kellogg, Idaho
Posts: 2
bearslife is on a distinguished road
Re:Inserting and displaying Unique Statistics from users viewing my site, problem

I am trying to figure out how I can insert user information only once
(ip,date,browser,referrer) etc... I don't want to have the user information inserted more than once into my mysql database table. Then I want to display it only once every visitor. I have the scripts working fine right now, but it enters and displays every hit to my site regardless if it is unique or not.

Below is my table in mysql:

CREATE TABLE `statistical` (
`id` int(11) NOT NULL auto_increment,
`ip` varchar(25) NOT NULL default '',
`date` varchar(50) NOT NULL default '',
`subfolder` varchar(65) NOT NULL default '',
`os` varchar(250) NOT NULL default '',
`referrer` varchar(250) NOT NULL default '',
PRIMARY KEY (`id`)
)

Here is my script used to insert the informaiton into the database:
"/astatistic.php"
PHP Code:
<?
$username 
"";
$password "";
$host "";
$database "";
mysql_connect($host,$username,$password) or die("Cannot connect to the database.<br>" mysql_error());
mysql_select_db($database) or die("Cannot select the database.<br>" mysql_error());

$ip $_SERVER['REMOTE_ADDR'];
$date date("D M j g:ia");
$subfolder $_SERVER['PHP_SELF'];
$os $_SERVER['HTTP_USER_AGENT'];
$referrer $_SERVER['HTTP_REFERER'];

$result=mysql_query("INSERT INTO statistical (ip, date, subfolder, os, referrer) VALUES ('$ip','$date','$subfolder','$os','$referrer')")or die("Insert Error: ".mysql_error());

?>
Thanks, and god bless, I really hope that someone can help me figure out how to place the user only oncel into my database and display only that once not five million of the same person stats. Thanks again.

Last edited by bearslife; 07-05-2005 at 06:09 AM. Reason: name change
bearslife is offline   Reply With Quote
Old 08-06-2004, 06:14 PM   #2 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Although using the users IP address isn't strictly the best way to go about it (because more than one user can access from the same IP), I suppose performing two queries per page would be the way you'd want to approach this. The first query simply looks up the users IP in the database, then if it doesn't exist, logic dictates that the second query is run.
bdl is offline   Reply With Quote
Old 08-06-2004, 06:53 PM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,710
redhead is on a distinguished road
It could be more specific if you'd extend that ie:
PHP Code:
$been_here mysql_query("SELECT id FROM statistical WHERE ip = \"$_SERVER['REMOTE_ADDR']\" AND os = \"$_SERVER['HTTP_USER_AGENT']\""); 
But then again, in these M$ days, this wouldn't catch that many if they were sharing IP.

And if the viewer were to have multiple boot options, this would srew it up aswell.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is online now   Reply With Quote
Old 08-07-2004, 07:58 AM   #4 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Depending on what you're looking to get our of the stats, you may also want to query the date. What if the same person views your site tomorrow, next week or 3 months from now?

Seems like a missed hit.

-r
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 07:15 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting