Post by Peter on Jul 28, 2006 6:26:59 GMT -8
Just a small script so you can add a visitor counter into the info center, this is not hosted, so you will need to host the PHP yourself, but it's very easy, you don't need a MySQL database.
Place this into a file and save it as "counter.php" (without quotes).
<?php
$DB = new SQLiteDatabase("counter.db.sqlite");
if($DB -> query("PRAGMA table_info(counter)") -> numRows() == 0){
$DB -> query("BEGIN;
CREATE TABLE counter(id INTEGER PRIMARY KEY, hits INT(11));
INSERT INTO counter (hits) VALUES('0');
COMMIT;
");
}
$DB -> query("UPDATE counter SET hits = hits + 1 WHERE id = 1");
$result = $DB -> query("SELECT * FROM counter WHERE id = 1");
if($result -> valid()){
$row = $result -> current();
$script = 'var nCell = document.getElementsByTagName("td");';
$script .= 'for(c = 0; c < nCell.length; c ++){';
$script .= 'if(nCell.item(c).vAlign == "top" && nCell.item(c).width == "40%"';
$script .= ' && nCell.item(c).innerHTML.match(/Total Members: /)){';
$script .= 'nCell.item(c).firstChild.appendChild(document.createElement("br"));';
$script .= 'nCell.item(c).firstChild.appendChild(document.createTextNode("Visitors: ';
$script .= number_format($row["hits"]) . '"));';
$script .= '}};';
echo $script;
}
?>
Upload it to your host that supports PHP 5 (check with your host or look in your CPanel area).
I recommend you create a directory to store these sort of codes in, as I may do a few more in the future, so maybe create a folder called "ProBoards", and in that folder create another called "Counter", place the counter.php file into that folder.
All that is left now is to get it displayed onto your forum, to do that, place this into your main footer, but just add the URL to the counter.php file...
<script type="text/javascript" src="URL TO counter.php"></script>
Simple counter
Place this into a file and save it as "counter.php" (without quotes).
<?php
$DB = new SQLiteDatabase("counter.db.sqlite");
if($DB -> query("PRAGMA table_info(counter)") -> numRows() == 0){
$DB -> query("BEGIN;
CREATE TABLE counter(id INTEGER PRIMARY KEY, hits INT(11));
INSERT INTO counter (hits) VALUES('0');
COMMIT;
");
}
$DB -> query("UPDATE counter SET hits = hits + 1 WHERE id = 1");
$result = $DB -> query("SELECT * FROM counter WHERE id = 1");
if($result -> valid()){
$row = $result -> current();
$script = 'var nCell = document.getElementsByTagName("td");';
$script .= 'for(c = 0; c < nCell.length; c ++){';
$script .= 'if(nCell.item(c).vAlign == "top" && nCell.item(c).width == "40%"';
$script .= ' && nCell.item(c).innerHTML.match(/Total Members: /)){';
$script .= 'nCell.item(c).firstChild.appendChild(document.createElement("br"));';
$script .= 'nCell.item(c).firstChild.appendChild(document.createTextNode("Visitors: ';
$script .= number_format($row["hits"]) . '"));';
$script .= '}};';
echo $script;
}
?>
Upload it to your host that supports PHP 5 (check with your host or look in your CPanel area).
I recommend you create a directory to store these sort of codes in, as I may do a few more in the future, so maybe create a folder called "ProBoards", and in that folder create another called "Counter", place the counter.php file into that folder.
All that is left now is to get it displayed onto your forum, to do that, place this into your main footer, but just add the URL to the counter.php file...
<script type="text/javascript" src="URL TO counter.php"></script>
Simple counter