Search…

X3 Photo Gallery Support Forums

Search…
 
User avatar
mindsuk
Experienced
Topic Author
Posts: 31
Joined: 22 Feb 2010, 16:03

visitor counter at the footer...

09 Jul 2012, 13:34

Hey Artur,

how do you add this nice visitor counter at the footer on your website??

greetings mindsuk
Attachments
Bildschirmfoto 2012-07-09 um 19.31.15.jpg
Bildschirmfoto 2012-07-09 um 19.31.15.jpg (4.03 KiB) Viewed 12320 times
 
User avatar
Artur
Imagevue PowerPack
Posts: 510
Joined: 20 May 2011, 03:17

Re: visitor counter at the footer...

09 Jul 2012, 16:17

Hello.
I have bought this file and edited it for my gallery :wink:
 
Eightkiller
Experienced
Posts: 116
Joined: 15 Jul 2012, 14:34

Re: visitor counter at the footer...

12 Nov 2012, 09:54

Hy, I also bought this counter, but the explanation on the "help file" is not really easy to understand (awkward english, you can easily misunderstand what is the meaning of it). Could you tell me what you did to merge it with the Imagevue Gallery (on the footer) or at least tell me which files i need to modify and where i must put the folders and files of the counter in my imagevue folder tree, then i hope i will manage to modify the files in order to make it work :)

Thanks in advance.
 
User avatar
Artur
Imagevue PowerPack
Posts: 510
Joined: 20 May 2011, 03:17

Re: visitor counter at the footer...

12 Nov 2012, 10:21

Please send me proof of purchase via PM.
The file needs to be deeply edited to fit the imagevue gallery. So I'll do this for you :wink:
 
margouillat
Experienced
Posts: 34
Joined: 31 Jul 2011, 09:20

Re: visitor counter at the footer...

21 Nov 2012, 07:15

same problem for me i've send you a PM
thanks, very nice work you do
Margouillat
loeildumargouillat.fr
 
User avatar
Artur
Imagevue PowerPack
Posts: 510
Joined: 20 May 2011, 03:17

Re: visitor counter at the footer...

19 Apr 2013, 12:36

I decided to post a basic tutorial how to make a simple visits counter (with total and today visits)
(Please note that I wrote this code quickly, without any tests. But it should work :lol: )


1. Create folder called "counter".


2. Open some script editor and create a new PHP file.

Always begin with "php" tag:
Code
<?php
Lets create some variables.
Code
$ip = $_SERVER['REMOTE_ADDR'];
$day = date('d');
$txt_file = "stats.txt";
$ip: it stores user IP address;
$day: this shows today date (only day as number);
$stats_file: the file that holds all visits and IP addresses.

Check if the stats file exists on the server. If not then create one:
Code
if(!file_exists($txt_file)){ 
   $fp = fopen($txt_file,"w");  
   fwrite($fp, $day . "#0#" . $ip); 
   fclose($fp); 
}
Load stats file:
Code
$stats_file = file_get_contents($txt_file);
Transform the file into an array (what is array?). In this way we have a quick access to all IPs, total and todays visits:
Code
$stats_array = explode('#', $stats_file);
The very first array always represents the last stored day. Lets separate it and remove from our IP's array:
Code
$last_day = array_shift($stats_array);
The second array always represents Total visits. Lets separate it, add todays visits and remove from our IP's array:
Code
$total_visits = array_shift($stats_array) + count($stats_array);
After that, the array contains only IPs.

Now we need to check if the last stored day is still today:
Code
if($day == $last_day){
If the day is today, we need to check whether user IP address was already stored in the stats file:
Code
if(!found_ip($ip, $stats_array)){
If not, then add this IP to the array
Code
array_push($stats_array, $ip);
Also increase total visits amount +1 :
Code
$total_visits ++;
Now we need to update our stats file and store our new IP address:
Code
file_put_contents($txt_file, $stats_file . "#" . $ip);
	}
If the day inside stats file was not the same as todays date (it means that the last visit was yesterday), we need to clear all IP from yesterday and update total visits:
Code
}else{
	$stats_array = array($ip);
	file_put_contents($txt_file, $day . "#" . $total_visits . "#" . $ip);
	$total_visits ++;
}

This is the function that is checking whether IP address is found in our IP's array:
Code
function found_ip($ip, $stats_array){
	foreach($stats_array as $stat){
		if($stat == $ip){
			return true;
		}
	}
	return false;
}
Lets count now all unique IPs from today. In this way you know how many people have visited your site today:
Code
$today_visits = count($stats_array);
The final step is the output for flash.
The output is styled by imagevue CSS. Make sure that the styles are in your stylesheet (Theme settings -> Edit Stylesheet).
You can change the output as you wish, just remember to not change $total_visits and $today_visits, as these variables are responsible for the visits numbers.
Code
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>';
Remember to close the PHP tag:
Code
?>
Give the file name "counter.php" and save it in "counter" folder.




3. Create flash file. Remember that it must be writen in ActionScript 2.0!

Go to first frame, click "Actions" (or hit F9) and write few lines of code:

First line creates a text field:
Code
var output_txt = this.createTextField("output_txt",1,0,0,10,10);
Now set the text filed that makes it able to display formated HTML text:
Code
output_txt.html = true;
output_txt.autoSize = true;
output_txt.multiline = true;
output_txt.selectable = false;
output_txt.styleSheet = _global.myCSS;
Lets create "LoadVars" (MORE INFO)
Specify what's happen when the communication between flash and PHP is finished (we just want to display loaded text into our text field):
Code
var my_lv:LoadVars = new LoadVars();
my_lv.onData = function(src:String) {
    if (src == undefined) {
        trace("Error loading content.");
        return;
    }
    output_txt.htmlText = src;
};
Now we can load the PHP file (remember that path to the file is related to the gallery path!) :
Code
my_lv.load("counter/counter.php", my_lv, "GET");
Save the file into "counter" folder, name it "counter.fla" and publish it (just create a SWF file).

Everything is ceded! :)



4. Now you should have folder called "counter", with 2 files inside: "counter.php" and "counter.swf".
Upload the folder on the server, go to your imagevue admin panel -> powerPack -> Footer -> Footer Content:
Specify path to the counter.swf file (f.ex: extras/userFiles/counter/counter.swf), change display type to "image" and save settings.

That's it!

-------------------------------------------------------------------------
Whole code:

PHP:
Code
<?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>';

?>
FLA:
Code
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");
Last edited by Artur on 20 Apr 2013, 01:31, edited 1 time in total.
 
User avatar
Andrew
Posts: 18
Joined: 16 Apr 2013, 08:36

Re: visitor counter at the footer...

19 Apr 2013, 15:28

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
Attachments
counter.zip
(951 Bytes) Downloaded 469 times
Last edited by Andrew on 19 Apr 2013, 19:47, edited 1 time in total.
 
User avatar
Andrew
Posts: 18
Joined: 16 Apr 2013, 08:36

Re: visitor counter at the footer...

19 Apr 2013, 19:42

Slightly altered script to use MySQL DB

create tables in the database:
File: base.php
Code
<?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);
?>
File: counter.php
Code
<?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>';
}
?>
File: counter.fla
Code
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");
I corrected the vertical position to -8

For set up styles
"Themes" > "Edit Stylesheet"
Code
.powerpack_footer{
	font-size: 14px;
	font-family: Arial;
	color: #9A9A9A;
}
.powerpack_footer_numbers{
	font-size: 14px;
	font-family: Arial;
	color: #FF9600;
}
And clear browser cache. :D

Result on site: http://24pic.ru

P.S. sorry for my bad english
Last edited by Andrew on 20 Apr 2013, 05:55, edited 4 times in total.
 
User avatar
Artur
Imagevue PowerPack
Posts: 510
Joined: 20 May 2011, 03:17

Re: visitor counter at the footer...

20 Apr 2013, 01:34

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
Edited the code (a little typo in syntax) :wink:

As for the styles - always remember to clear browser cache.
 
User avatar
Andrew
Posts: 18
Joined: 16 Apr 2013, 08:36

Re: visitor counter at the footer...

20 Apr 2013, 02:47

Artur wrote:As for the styles - always remember to clear browser cache.
oops :oops:
Thank you so much!
 
jm26200
Experienced
Posts: 39
Joined: 19 Jul 2008, 02:30

Re: visitor counter at the footer...

17 May 2013, 14:10

hi all

i don't understand i have same counter.php same base.php for create table and i see table exist put swf with ActionScript 2.0!
in fla but on my footer nothing always empty

Image

Image

if u have solution i take ;) thanks

take care
 
User avatar
Andrew
Posts: 18
Joined: 16 Apr 2013, 08:36

Re: visitor counter at the footer...

17 May 2013, 19:20

jm26200, Try to use my counter.swf
counter.zip
(999 Bytes) Downloaded 579 times
 
jm26200
Experienced
Posts: 39
Joined: 19 Jul 2008, 02:30

Re: visitor counter at the footer...

18 May 2013, 00:29

hi Andrew ty

Now 6h30 morniong in France i go take my breakfeast and i try donwload ur swf but i doubt ... coz make sw same coçlme in frame 1 action same no error scropt 2 i i hope ur is good i appreciate ur help ty and take care byeee i come after fir say if is good or no ...

sorry for my English i know very bad may be i treys but u make man hammy when i read ur post ty @@++
 
jm26200
Experienced
Posts: 39
Joined: 19 Jul 2008, 02:30

Re: visitor counter at the footer...

18 May 2013, 03:09

Andrew wrote:jm26200, Try to use my counter.swf
counter.zip

u make me hayy now i seee thnx u very much for hemlp me and give ur swf i don't know wht mine no good with adobe flash CS3 pro ???

good weeek end here more rain no good but cool counter its ok ty

take care good luck

Image

JM
 
User avatar
Andrew
Posts: 18
Joined: 16 Apr 2013, 08:36

Re: visitor counter at the footer...

18 May 2013, 13:48

Hi jm26200!

I'm from Russia and my English is not better than you )))))
I am glad that you all made ​​it!
I compiled SWF in Adobe Flash Professional CS6 12.0.2.529

Andrew