What a hell am i doing wrong ? !! please help !

Started on the old forum in June 2011 · view the original in the archive · old links redirect here

#script #unique #visits

17 replies · 723 views · started 15 years ago · 1 min read

7 participants
just_m3. Developer · 199 posts #1

i made a script that counts unique visits and user/ip visits the problem is that on my host it counts +2 instead +1 how its written in the script watch and give a reply 🙂

<?php
// Your MySQL database host
$db_host = "localhost";
// Your MySQL database username
$db_user = "user";
// Your MySQL database password
$db_pass = "password";
// Your MySQL database name
$db_name = "name";

$conexiune = mysql_connect($db_host,$db_user,$db_pass) or die('I can\'t connect to MySQL server!');
$conexiune1 = mysql_select_db($db_name, $conexiune) or die('Database cannot be found');
//if(!$conexiune1){die("Sorry to many conection it is possible that we are flooded");}

$server=$_SERVER['REMOTE_ADDR'];

$check=mysql_fetch_array(mysql_query("SELECT ipuniq FROM ip_logss WHERE ipuniq='".mysql_real_escape_string($server)."'"));
$cnt=mysql_fetch_array(mysql_query("SELECT total_per_user FROM ip_logss WHERE ipuniq='".mysql_real_escape_string($server)."'"));

$total_per_user=$cnt[0]+1;

if(empty($check[0])){$proc_index=mysql_query("INSERT INTO  ip_logss SET ipuniq='".mysql_real_escape_string($server)."'");}

else{$proc_total=mysql_query("UPDATE ip_logss SET total_per_user=".$total_per_user." WHERE ipuniq='".mysql_real_escape_string($server)."' ");}

$check_count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ip_logss"));

echo'<small>ToTal Unique Hits '.$check_count[0].'</small><br/><small>Your visits here '.$cnt[0].'</small><br/>'; 

?>

mysql database here

CREATE TABLE IF NOT EXISTS `ip_logss` (
  `ipuniq` varchar(500) NOT NULL DEFAULT '',
  `total_per_user` varchar(500) NOT NULL DEFAULT '',
  PRIMARY KEY (`ipuniq`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

here is the link to the script running http://celx.eu/visits.php

Added after 6 minutes:

btw when visiting http://celx.eu/visits.php give 3 or more reloads on page and see how it acts ,,

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

something else Fellow · 2,296 posts #2

could try:

else{$proc_total=mysql_query("UPDATE ip_logss SET total_per_user=total_per_user+1 WHERE ipuniq='".mysql_real_escape_string($server)."' ");}

p.s your probably better off setting: ipuniq varchar(500) NOT NULL DEFAULT '', total_per_user varchar(500) NOT NULL DEFAULT '',

to total_per_user int(10) NOT NULL DEFAULT '0', ipuniq varchar(15) NOT NULL DEFAULT '',

just_m3. Developer · 199 posts #3

finally it works thanxxxx 😛

Added after 6 minutes:

it's started to add+2 again 🙂) lol i don't know what is wrong i gived the code to someone else to try it on other server and its working fine ..

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

arnage Lead · 811 posts #5

Well try to limit it. 🙂

 $check_count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ip_logss Limit 1"));
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
just_m3. Developer · 199 posts #6
 $check_count = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ip_logss Limit 1")); 

$check_count is for counting unique visits why should i limit ?

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

arnage Lead · 811 posts #7

Limit query, it counts 2+2... on refresh so limit it to 1. Try it. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
just_m3. Developer · 199 posts #8

Loony wrote: i was having the same problem on my server it seemed the only way i could fix it would be to make the 1 a variable

$total_per_user=$cnt[0]+1; 

so try change it to

$add = 1;
$total_per_user=$cnt[0]+$add;

i already tried that it's not working i think my host is dumb 🙂 ..

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

just_m3. Developer · 199 posts #10

neah .. ain't working i think i will just use unique counter and thats it .. at least untill i change my host thanks all

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

morency Senior · 488 posts #11

use histats.com , alternative ways , better results 🙂

whatever , WapPortal Free wap downloads work , increment with one on every refresh . just on begin dont show anything so change DEFAULT do 0.

one short question : Do you think your users are really interested in this statistics ?!

Unamos los corazones,hoy todos somos multicolores!

just_m3. Developer · 199 posts #12

morency wrote: use histats.com , alternative ways , better results 🙂

whatever , WapPortal Free wap downloads work , increment with one on every refresh . just on begin dont show anything so change DEFAULT do 0.

one short question : Do you think your users are really interested in this statistics ?!

DEFAULT is changed to 0 ,, some of them may be don't you think ? 🙂) anyway i removed that .. , and about counting, sometimes counts right and then it gets dizzy at least i think 😀 ... it's a server side error most sure // about 2 months ago had an unbelievable server side error so when i requested user ip was showing me the host ip more precisely my site ip .. can you believe that ? 🙂

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

just_m3. Developer · 199 posts #14

anyway the final script working (not on my host 🙁 ) ..

is here

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

ksg91 Developer · 162 posts #15

How is host suppose to affect that? >_> And sometime working and sometime not, means a single request to that page might be going twice.. maybe network issue

Follow me @ksg91 | My Blog: http://ksg91.com | Nokia Blog: http://NokiaTips.in

Jerson Developer · 70 posts #16

Why dont you log user ip and browser in the database. Then code like this

if(mysql_query(select from visitors where ip = '$ip', browser ='$browser', time = '$time')); { } else{ code here to add to database. }

then count for whois online today.

just_m3. Developer · 199 posts #17

i needed a simple logs code 🙂 its working ..

How is host suppose to affect that? >_> And sometime working and sometime not, means a single request to that page might be going twice.. maybe network issue

it's not network issue because is acting same at all users the code i tested is exactly the one i uploaded here it should work .. it's counting unique visits but on my host it's failing at counting / user visits ..

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close