View Full Version : Hit Counter
I just wrote my own hack for version 1.1.5 that keeps
track of hit counts. The problem is, everytime
I update the database field
(counter=counter+1)
It winds up incrementing in intervals of 2
55...57...59...61
I put the code in index.php3
I made sure I placed the code in after
if ($action=="showforums") {
...
...
...
$DB_site->query("UPDATE hitcounter SET counter=counter+1");
...
...
}
why is this happening?
PS
Here is how I created the DB Table
$DB_site->query("CREATE TABLE hitcounter (counter MEDIUMINT (8) UNSIGNED DEFAULT '0' not null)");
[Edited by HarryPotter on 01-19-2001 at 10:04 AM]
Can someone please help??????!!!!!!!!!!!
26 Views and no replies??
erm, there's no logic what so ever to your problem
Heh, I know there is no logic. Thats why I am asking.
I was wondering...maybe somehow the index.php file is being called twice for each page refresh? Which would mean that the PHP code is very inefficient. Thats the only explanation I can come up with.
PLEASE HELP!!!!
I have created a test script that simply
increments the counter by 1 and displays the vallue.
And it works fine
But when I place the same code in the index.php file,
the value of the increment is doubled!
At this point, i am convinced that this is being caused
by the ineffecieny of the index.php file itself.
I am under the assumption that the index.php file calls itself while loading causing a double increment.
If this is true (and I apologize if I am wrong), can someone
explain what purpose it servers to double the load time of a page by calling it 2X?
And how can I get around this problem?
We need to see the code modifications you made and how your storing the data in the database (and where) before we can even begin to think about solving it.
This may have been what Menno meant about "there is no logic".
Anyway do not post the entire index.php but the lines before and after your modifications and the modifications themself. Only then will anyone be able to help you.
ok, this is how I created the tabled needed for my HitCounter HACK:
$DB_site->query("CREATE TABLE hitcounter (counter MEDIUMINT (8) UNSIGNED DEFAULT '0' not null)");
Here is the code/hack:
--->modifications for Index.php
The following code is placed right after the
require("global.php3");
//hit counter hack
$hitcounter=$DB_site->query("SELECT hitcounter.counter
FROM hitcounter");
$value=$DB_site->fetch_array($hitcounter);
$hitcountervalue = $value[counter];
//END hit counter hack
...
...
...
The following line is placed right after
if ($action=="showforums") {
$DB_site->query("UPDATE hitcounter SET hitcounter.counter = hitcounter.counter + 1");
...
...
...
The End
There is the code you asked for....This is driving me crazy. It makes no sense why this is happeneing.
Like I said before, when I put the same code in a seperate php file (test.php), it works fine.
I only have this problem when the code is placed in index.php
Well, I seem to have gotten no useful replies here :(
Im gonna ask one last time for help regarding this topic....anyone??? Please???
Ed???????????????
You either put the code in a while or doubled up the code. Comment it out of index.php and see if it gets upped by 1 or none.
I commeneted it out and now it doesnt increment at all.
And I made sure its not in any loop.
If you look at the previous msg above, yu will see where the icrement is taking place, and it is outside of a loop!
Any other ideas?
well like I said before, I created a test script and in the test script, I do not have these probelms...These
probelms occur only when the code is inserted into
index.php
how about just requring your test script below the require config.php and see if that helps.
I am having this same problem kinda.
I used the weblog script.
Somehow it is loading the page twice, I put on my index page a simple script to log refering url, browser, ip etc.
Then in mysql when I check I get 2 entrys per visitor, one will show the url they came from, the second is from my site.
So I know something with global.php is causing it to load twice.
It is not in a while loop either.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.