php counters
Moderator: General Moderators
php counters
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
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
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>";
?>
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>";
?>
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..
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.
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>";
?>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.