View Full Version : In a PHP "Affiliate Application" how I count total unique visitors came from a url eg
leonidassavvides
03-31-2009, 03:48 PM
In a PHP "Affiliate Application" how I count total unique visitors came from a url eg.
http://www.example.com/index.php?aid=12345 ? this url may be in many websites ...
I must use a db table field eg countUniqueVisitors ?
CrazyChop
03-31-2009, 04:26 PM
There are two ways to do it.
Method #1 - One way to do it is to give each affiliate an ID. Then basically just increment the number.
Method #2
However, this won't help if someone keeps on refreshing the page. You would need a log, which log every-time someone comes to the site through a particular affiliate. You will need to log the IP address (that is not 100% reliable though) and time of visit, Whenever there's a hit, do a SQL query and check the IP address -- if it has been logged before, don't log it. Or else, log it in.
You may want an expiry date for unique visitors; if so, you may wish to specify a date range inside your SQL for detecting duplicated visitors.
A SQL query "SELECT COUNT(*) FROM AFFILIATES_VISITORS WHERE ID = $wanted_ID" will give the unique visitors
If you wish to prune the database, say, after 6 months, or monthly, you can have a cron job which delete all entries older than 6 months, but before that do a final tally (as in Method #1) and add it to a running total of total unique visitors.
leonidassavvides
03-31-2009, 06:43 PM
How I get IP for a webuser in PHP ?
When IP is the same but date of 3mo past[cookie aff], I must log it as another hit or not ?
Lpe04
03-31-2009, 10:49 PM
Method #1 - One way to do it is to give each affiliate an ID. Then basically just increment the number.
This won't track uniques though. This will get all hits but you need something else for uniques, like setting cookies.
Cheers,
CrazyChop
04-01-2009, 08:04 AM
This won't track uniques though. This will get all hits but you need something else for uniques, like setting cookies.
Cheers,
Not an expert on this subject really :) but IP addresses are unreliable (due to NAT) and cookies can be flushed; yep, you should check for if the user is unique before incrementing the DB, may bad.
leonidassavvides
04-05-2009, 01:35 PM
IP Addresses has any relation with tel line ? if i change connection (tel line or network) via a laptop IP changes ?
CrazyChop
04-06-2009, 11:27 AM
IP Addresses has any relation with tel line ? if i change connection (tel line or network) via a laptop IP changes ?
Ah no...
IP addresses have nothing to do with phone lines and are solely abstract. They exist in 4 classes, with each classes having different number of potential addresses. The 4 classes are known as A, B, C and D. I forgot what those classes are for, but one is for education institutes and one is for commerical IP while others are reserved.
As IP addresses were 32-bit in length, the experts assumed that there were enough to go around. However, the unexpected commercialization caused commerical IP addresses to run out. So what is done nowadays is called Network Address Translation (NAT). Each Internet rovider has an IP (a real IP) while each of its customer has a 'temporarily IP' assigned base on their own rules. Broadband users may get a IP when they log on while cable-users get one when depending on their land line.
That user's IP however is not unique - it is entirely possible that someone else has your IP address. However, from the first three (or two) set of digits in the IP address, it is possible to determine which is your Internet provider - they will send the entire address over tot the provider, which will do some internal magic to determine to whom the IP really represents. If the IP is sent to some other provider, someone else would get the internet packets.
What happens here is Network Address Translation. Basically, the provider/gateway tags your MAC (machine address code, based on your ethernet card) which is an unique number (throughout the world, 99.99) to a dynamically assigned IP address (which is not unique throughout the world) and send it out. When the gateway/provider received a packets, it will look up the MAC address by the IP given, find out where you are, under-go some more ethernet/LAN mumbo-gumbo (which I can't remember very well) and send the packet to you.
Which is why, until IP 62-bit come out, tracking people base on IP doesn't work. It at most will tell you his country and his service provider, and from that point on it could be anyone within that pool of people.
Hope this helps
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.