Hey Artur,
how do you add this nice visitor counter at the footer on your website??
greetings mindsuk
X3 Photo Gallery Support Forums
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$day = date('d');
$txt_file = "stats.txt";
if(!file_exists($txt_file)){
$fp = fopen($txt_file,"w");
fwrite($fp, $day . "#0#" . $ip);
fclose($fp);
}
$stats_file = file_get_contents($txt_file);
$stats_array = explode('#', $stats_file);
$last_day = array_shift($stats_array);
$total_visits = array_shift($stats_array) + count($stats_array);
if($day == $last_day){
if(!found_ip($ip, $stats_array)){
array_push($stats_array, $ip);
$total_visits ++;
file_put_contents($txt_file, $stats_file . "#" . $ip);
}
}else{
$stats_array = array($ip);
file_put_contents($txt_file, $day . "#" . $total_visits . "#" . $ip);
$total_visits ++;
}
function found_ip($ip, $stats_array){
foreach($stats_array as $stat){
if($stat == $ip){
return true;
}
}
return false;
}
$today_visits = count($stats_array);
echo '<span class="powerpack_footer">Site Wisited Total: </span><span class="powerpack_footer_numbers">' . $total_visits . '</span>, <span class="powerpack_footer">Today: </span><span class="powerpack_footer_numbers">' . $today_visits . '</span><span class="powerpack_footer"> | Artur Filipiak | Photography | Copyrights 2013</span>';
?>
var output_txt = this.createTextField("output_txt",1,0,0,10,10);
output_txt.html = true;
output_txt.autoSize = true;
output_txt.multiline = true;
output_txt.selectable = false;
output_txt.styleSheet = _global.myCSS;
var my_lv:LoadVars = new LoadVars();
my_lv.onData = function(src:String) {
if (src == undefined) {
trace("Error loading content.");
return;
}
output_txt.htmlText = src;
};
my_lv.load("counter/counter.php", my_lv, "GET");
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$day = date('d');
$txt_file = "stats.txt";
if(!file_exists($txt_file)){
$fp = fopen($txt_file,"w");
fwrite($fp, $day . "#0#" . $ip);
fclose($fp);
}
$stats_file = file_get_contents($txt_file);
$stats_array = explode('#', $stats_file);
$last_day = array_shift($stats_array);
$total_visits = array_shift($stats_array) + count($stats_array);
if($day == $last_day){
if(!found_ip($ip, $stats_array)){
array_push($stats_array, $ip);
$total_visits ++;
file_put_contents($txt_file, $stats_file . "#" . $ip);
}
}else{
$stats_array = array($ip);
file_put_contents($txt_file, $day . "#" . $total_visits . "#" . $ip);
$total_visits ++;
}
function found_ip($ip, $stats_array){
foreach($stats_array as $stat){
if($stat == $ip){
return true;
}
}
return false;
}
$today_visits = count($stats_array);
echo '<span class="powerpack_footer">Site Wisited Total: </span><span class="powerpack_footer_numbers">' . $total_visits . '</span>, <span class="powerpack_footer">Today: </span><span class="powerpack_footer_numbers">' . $today_visits . '</span><span class="powerpack_footer"> | Artur Filipiak | Photography | Copyrights 2013</span>';
?>
var output_txt = this.createTextField("output_txt",1,0,0,10,10);
output_txt.html = true;
output_txt.autoSize = true;
output_txt.multiline = true;
output_txt.selectable = false;
output_txt.styleSheet = _global.myCSS;
var my_lv:LoadVars = new LoadVars();
my_lv.onData = function(src:String) {
if (src == undefined) {
trace("Error loading content.");
return;
}
output_txt.htmlText = src;
};
my_lv.load("content/counter.php", my_lv, "GET");
<?php
$date = date('Y-m-d', time());
$db = mysql_connect('127.0.0.1', 'user', 'pass'); //Enter your information for the connection
mysql_select_db("youbase"); //Enter the name of your database
mysql_query("DROP TABLE `list_ip`");
mysql_query("DROP TABLE `statistics`");
mysql_query("CREATE TABLE `list_ip` (`id` INT(10) NOT NULL AUTO_INCREMENT,
`ip` TEXT(15) NOT NULL,
`date` TEXT(10) NOT NULL,
PRIMARY KEY(`id`))");
mysql_query("CREATE TABLE `statistics` (`hosts` INT(10) NOT NULL,
`hits` INT(10) NOT NULL,
`total` INT(15) NOT NULL,
`date` TEXT(10) NOT NULL)");
mysql_query("INSERT INTO `statistics` (`hosts`, `hits`, `total`, `date`) VALUES (0,0,0, \"$date\")");
mysql_close($db);
?>
<?php
$date = date('Y-m-d', time()); //today's date
$db = mysql_connect('localhost', 'user', 'pass'); //Enter your information for the connection
mysql_select_db("youbase"); //Enter the name of your database
mysql_query("DELETE FROM `list_ip` WHERE (`date`!=\"$date\")"); //remove the rows where no current date
mysql_query("UPDATE `statistics` SET `hosts`=0, `hits`=0 WHERE (`date`!=\"$date\")"); //nulled hosts and the hits of today
mysql_query("UPDATE `statistics` SET `date`=\"$date\""); //change the date to today's
$ip = $_SERVER['REMOTE_ADDR']; //get user ip
$result = mysql_query("SELECT * FROM `list_ip` WHERE (`ip`=\"$ip\") "); //checking that it exists in the database
$row = mysql_num_rows($result);
if ($row > 0) //if host exist
{
$result = mysql_query("SELECT `hosts`, `hits`, `total` FROM `statistics`");
$row = mysql_fetch_array($result);
$new_hits = ++$row['hits']; //increase hits to date
mysql_query("UPDATE `statistics` SET `hits`=\"$new_hits\""); //update data
output($row['hosts'], $new_hits, $row['total']); //call the output
} else //if host not exist
{
mysql_query("INSERT INTO `list_ip` (`ip`, `date`) VALUES (\"$ip\", \"$date\")") or die(mysql_error());
$result = mysql_query("SELECT `hosts`, `hits`, `total` FROM `statistics`");
$row = mysql_fetch_array($result);
$new_hosts = ++$row['hosts']; //increase the hosts for today
$new_hits = ++$row['hits']; //increase hits to date
$new_total = ++$row['total']; //increase the number of visits
mysql_query("UPDATE `statistics` SET `hits`=\"$new_hits\", `total`=\"$new_total\""); //update data
output($row['hosts'], $new_hits, $new_total); //call the output
}
mysql_close($db);
function output($hosts, $hits, $total)
{
echo '<span class="powerpack_footer">Site Visited Total: </span><span class="powerpack_footer_numbers">' . $total . '</span><span class="powerpack_footer">, Today: </span><span class="powerpack_footer_numbers">' . $hosts . '</span><span class="powerpack_footer">, Today Hits: </span><span class="powerpack_footer_numbers">' . $hits . '</span><span class="powerpack_footer"> | © 24pic, 2013</span>';
}
?>
var output_txt = this.createTextField("output_txt",1,0,-8,10,10);
output_txt.html = true;
output_txt.autoSize = true;
output_txt.multiline = true;
output_txt.selectable = false;
output_txt.styleSheet = _global.myCSS;
var my_lv:LoadVars = new LoadVars();
my_lv.onData = function(src:String) {
if (src == undefined) {
trace("Error loading content.");
return;
}
output_txt.htmlText = src;
};
my_lv.load("extras/userFiles/counters/counter.php", my_lv, "GET");
.powerpack_footer{
font-size: 14px;
font-family: Arial;
color: #9A9A9A;
}
.powerpack_footer_numbers{
font-size: 14px;
font-family: Arial;
color: #FF9600;
}
Edited the code (a little typo in syntax)Andrew wrote:Thanks a lot!
counters are displayed but do not work.
on different computers show different values.
on the first machine always shows Total: 1 Today: 1
on the second computer always shows Total: 2 Today: 2
I have not been able to create styles
oopsArtur wrote:As for the styles - always remember to clear browser cache.
Andrew wrote:jm26200, Try to use my counter.swf