Page 1 of 1

php counters

Posted: Sat Jan 04, 2003 2:26 pm
by thindery
well i did one of these easy php counters. and it works perfectly. the page for it is

http://thindery.deafening-urge.net/php/counter.php

there is one thing that i wanted to do, but i don't know how to do it. how can i have those numbers show up on a different page? i wanted to put those counts on my index page, or a different page other than the counter.php. i am pretty sure that you can do it, i just don't know how to do it. thanks for any help

tylor

Posted: Sat Jan 04, 2003 2:41 pm
by Elmseeker
You would pull the information from the file or database on other pages in the same you did it for this one. Are you using a file or a db for storing the counter information? If you post your PHP code in here it would make it a bit easier to help you out. ;)

Posted: Sat Jan 04, 2003 5:55 pm
by thindery
I am using a file to store the data.

Here is the whole code for counter.php::

<?php

//**********************************//
// Easy Counter script! //
// Author: Alex Walton //
// E-Mail: genshibakudan@hotmail.com//
// Date: 26.4.02 //
//**********************************//



// You can edit the variables below \/

$message1 = "There have been"; // first message section \/
$message2 = " visitors to this page."; // second message section [$message1 $count $message2]
$bold = "1"; // if 1, the numbers are bold, if 0 nothing is bold
$font = "verdana"; // The font name
$fontsize = "1"; // The size of the font
$textcolor = "#006699"; //The color of the $message1 and $message2 (HEX)
$numbercolor = "#006699"; //The colour of the numbers (HEX)
$numberglow = "0"; //If 1, the numbers glow, if 0, they don't. - If enabled, the layout changes =( [message1 \n count\n message2] I'm a PHP n00b, if you know how to fix this plz e-mail me
$glowcolor = "#0000FF"; //The colour of the glow

// Don't edit anything below this line unless you know what you're doing

$fp = fopen("count.txt","r+");
flock($fp,1);
$count = fgets($fp,6);
$count += 1;
rewind($fp);
fputs($fp,$count);
flock($fp,3);
fclose($fp);

if ($bold == "1"){
$bold1 = "<b>";
$bold2 = "</b>";
} elseif ($bold == "0"){
$bold1 = "";
$bold2 = "";
}
if ($numberglow == "1"){
$glow1 = "<table STYLE=width:100%;filter:GLOW(color=$glowcolor,strength=#+9)>";
$glow2 = "</table>";
} elseif ($numberglow == "0"){
$glow1 = "";
$glow2 = "";
}
print "<font face='$font' size='$fontsize' color='$textcolor'> $message1 </font><font face='$font' size='$fontsize' color='$numbercolor'>$glow1$bold1$count$bold2$glow2</font><font face='$font' size='$fontsize' color='$textcolor'> $message2</font>";
?>

Posted: Sat Jan 04, 2003 6:06 pm
by Gen-ik
If you want the count data to appear on every page just include this code in every page.. and place it where you want the count text to appear..

Code: Select all

<?php

$message1 = "There have been"; // first message section \/ 
$message2 = " visitors to this page."; // second message section [$message1 $count $message2] 
$bold = "1"; // if 1, the numbers are bold, if 0 nothing is bold 
$font = "verdana"; // The font name 
$fontsize = "1"; // The size of the font 
$textcolor = "#006699"; //The color of the $message1 and $message2 (HEX) 
$numbercolor = "#006699"; //The colour of the numbers (HEX) 
$numberglow = "0"; //If 1, the numbers glow, if 0, they don't. - If enabled, the layout changes =( [message1 \n count\n message2] I'm a PHP n00b, if you know how to fix this plz e-mail me 
$glowcolor = "#0000FF"; //The colour of the glow 

$fp = fopen("[color=red]count.txt[/color]","r+"); 
flock($fp,1); 
$count = fgets($fp,6); 
fclose($fp); 

if ($bold == "1"){ 
$bold1 = "<b>"; 
$bold2 = "</b>"; 
} elseif ($bold == "0"){ 
$bold1 = ""; 
$bold2 = ""; 
} 
if ($numberglow == "1"){ 
$glow1 = "<table STYLE=width:100%;filter:GLOW(color=$glowcolor,strength=#+9)>"; 
$glow2 = "</table>"; 
} elseif ($numberglow == "0"){ 
$glow1 = ""; 
$glow2 = ""; 
} 
print "<font face='$font' size='$fontsize' color='$textcolor'> $message1 </font><font face='$font' size='$fontsize' color='$numbercolor'>$glow1$bold1$count$bold2$glow2</font><font face='$font' size='$fontsize' color='$textcolor'> $message2</font>"; 

?>
Make sure the pages are in the same directory as the count.txt file though.
If they are not you will have to replace the count.txt part of the code and include the path... like this for example... ../afolder/count.txt ... so that it points towards the count.txt file.

Posted: Sat Jan 04, 2003 7:13 pm
by thindery
i tried that, but it still doesn't work. ne other ideas? or i will just get a new code

Posted: Sat Jan 04, 2003 7:46 pm
by Gen-ik
Are you trying to have the count.txt displayed on each page.. or do you want each page to have it's own counter?

Posted: Sat Jan 04, 2003 8:03 pm
by thindery
i am just going to have the counts displayed on one page. my main page of my website. could the problem be that my main page is html? when i worked on this counter before the page with the whole code was a php file, and it worked then. should i try to save it as php? thanks for all ur help

tylor

Posted: Sat Jan 04, 2003 8:12 pm
by Elmseeker
Yeah, put Gen-Ik's code in the main page and rename it from being an html file to being a php file and you should be ok. :)

Posted: Sat Jan 04, 2003 9:04 pm
by Gen-ik
Doh! You weren't using a PHP!! Sorry dude didn't know that.

If you find the counter isn't going up any more then try using your original code.. in a .php page :roll: