How to do it? Using the database.

  • absolutely right - no way. It is possible to tinker with cookies, etc., but as you know, cookies are cleaned, changed by handles, etc. etc. IP is also not an option - not all have a static IP (moreover, most of them have a dynamic IP) - Zowie
  • It is clear only relative. - Oleg
  • @exec thanks a lot (you know what for). - ReinRaus
  • @ReinRaus :) - Oleg

3 answers 3

If the page is shown only to authorized users, then you can make the number of views very unique. :-))) In general, of course, each view is so unique, even if it is already the fifth time from the same person. I would have counted. :-)

  • Philosophical approach. :-) - Angelina_Jo
  • @Angelina_Jo, I was on philosophy today. Do not remind. And here, too, did not hear anything new. But +100 for the desire to help. - Oleg
  • @Angelina_Jo, there is only one drawback here - to force the user to register (or at least log in using VC, FB and others). - Dex
  • Yes, it is impossible for the absolute majority to do it, but our problems do not interest them ... - Zowie
  • @Dex @AlexWindHope And if you force you to choose or enter your date of birth, attach an IP and get a hash? -))) Uniqueness is violated only if in the same family twins or if by some miracle the same ip is given to two people with the same date of birth or a collision occurs. -) - Angelina_Jo

User uniqueness can be defined in two ways (known to me):

  • IP
  • Cookie

You can also use them in conjunction, analyze the browser, etc. etc.

Consider the first point: the visitor's IP is stored in $_SERVER['REMOTE_ADDR'] . When you load the page you need to analyze the value of this variable and, if such an ip is not found in the database, then add it. For example: A table in mysql will look like: id | page_name | ip

 $page_name = "имя_страницы" $ip = $_SERVER['REMOTE_ADDR']; $fetch = mysql_query("SELECT * FROM `table` WHERE ip ='".$ip."' AND page_name='".$page_name."'") or die(mysql_error()); //Если такого айпи нет в базе, то делаем инсерт if ( mysql_num_rows($fetch) == 0 ) { mysql_query("INSERT INTO uniquehits(ip, page_name) VALUES('$ip', '$page_name')") or die(mysql_error()); } 

You can get the number of unique views using the query:

 $counttotal = mysql_query("SELECT count(*) cnt FROM uniquehits WHERE page_name='".$page_name."'") or die(mysql_error()); 

Consider the second point:

 // Проверяем, был ли уже установлен Cookie. // Если нет, то устанавливаем // С временем жизни до 2029 года if (!isset($_COOKIE['visited'])) setcookie("visited","1",0x6FFFFFFF); 

Check whether cookies are installed using: @ $ _ COOKIE ['visited']


As already mentioned, there is no ideal option. IP may change, cookies can be deleted, but such an analysis will give you at least some approximate information.

  • Thanks for the effort, of course, but I did not recognize anything new. - Oleg
  • IP - @Vitalii Maslianok, for example, I have a beeline 3G modem. Further explain about the IP? (At ppp0 address 172.19.188.96) - alexlz
  • I would put a cookie on my first visit and remember the ip, then I would trust the cookie, if not, I would search for the ip in the database. I have already said that this method does not claim to be 100% (or even 90%) correct ... But it will give an understanding of the overall situation. Want the best possible results - put counters from Google || Yandex - Vitalii Maslianok

This is not an answer. Just maybe a lot of letters will be, so I write in response. As we all see the problem of user identification is still standing. The other day I asked a question to which I never received a satisfying answer. Comrades, minds, hashkodovtsy, ... let's solve the issue of identification of a person in the network without registration and all sorts of inputs through social networks. The same Google and Yandex do not ask for any registration. It is clear that there are considerable bases, but they are designed for the entire Internet. Let's find the best solution for a simple service, and not a giant like Google? If not ip and not cookies and not sotsialki what?

  • Yes, there is no solution that provides protection from all tricks (and even not all, too). Determine for yourself what is necessary and what mistakes to consider acceptable. - alexlz
  • In the meantime, we are waiting for the time when each inhabitant of the planet will embed an identifier directly into the body, then this ID will be used to access the Internet and be transmitted in a super global array. :-) - Angelina_Jo
  • @Angelina_Jo, geolocation can be considered as another step towards this. Naturally, these are extra gestures from a person, a rather controversial method, but it can also be considered. - Dex
  • @Dex - the user's location is also not an indicator. And what if a person, for example, is traveling in a train, or has left a friend from his computer or from a cafe from his laptop? =) In fact, as rightly noted by @alexlz - there is no 100% correct solution and, so far, it cannot be. Of course, if you put together all the approaches - we will get the most fitting result, but absolutely true, so far, it is impossible to obtain. @ Vitaly Kustov - mix everything and make no profit; DDD - Zowie
  • @AlexWindHope, I have April 1st, at least 25 minutes will definitely be there, so mix and mix. You are right, everything can be bypassed. - Dex