Problems with hit counter, Please Help

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
PsychoticLucky7
-


Joined: 18 Aug 2004
Posts: 15

PostPosted: Sat Nov 20, 2004 12:44 am    Post subject: Problems with hit counter, Please Help Reply with quote

I am hosting my own site and my own hit counter, the counter works but I cannot get it to add leading zeros to the displayed mumber. Lets say that I have had 3 people on my site, and instead of the counter displaying 3, I would like it to display 0003. I've tried to put the zeros in the txt file but the php script delets them and displays 3. Can anyone help?

Code:

<html>
<body bgcolor="black">
<?
$dj = "hits.txt";
$fp = fopen($dj,"rb");
$kj = trim(fread($fp,filesize($dj)));
if ($kj != "") $kj++;
else $kj = 1;
@fclose($fp);
$fp = fopen($dj,"w");
@fputs($fp,$kj);
for($x=0;$x<strlen($kj);$x++) {
$img2 = substr($kj,$x,1);
$count .= "<img src='images/$img2.gif'>";
}
@fclose($fp);
echo "$count";
  ?>
</body>
</html>

_________________
InSaNiTy Is A gIfT!
Back to top View user's profile Send private message AIM Address
k1ll3rdr4g0n
-


Joined: 04 Jul 2004
Posts: 609

PostPosted: Sat Nov 20, 2004 2:36 am    Post subject: Reply with quote

Code:
<html>
<body bgcolor="black">
<?
$dj = "hits.txt";
$fp = fopen($dj,"rb");
$kj = trim(fread($fp,filesize($dj)));
if ($kj != "") $kj++;
else $kj = 1;
@fclose($fp);
$fp = fopen($dj,"w");
@fputs($fp,$kj);
for($x=0;$x<strlen($kj);$x++) {
$img2 = substr($kj,$x,1);
$count = "<img src='images/$img2.gif'>";
}
@fclose($fp);
echo "000" . $count;
  ?>
</body>
</html>


Try that.....
_________________
Back to top View user's profile Send private message AIM Address
PsychoticLucky7
-


Joined: 18 Aug 2004
Posts: 15

PostPosted: Sat Nov 20, 2004 2:42 am    Post subject: Reply with quote

k1ll3rdr4g0n wrote:

Try that.....

Thanks for the help, but all it did was push the number over a couple of spaces and displayed empty space in the place of the zeros...

-PsychoticLucky7
_________________
InSaNiTy Is A gIfT!
Back to top View user's profile Send private message AIM Address
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Sat Nov 20, 2004 4:20 am    Post subject: Reply with quote

Thats because their is a space between the 000 , try this. LateR!

Edit: Try Aprelium's code instead , I got nothing...


Last edited by TRUSTAbyss on Sat Nov 20, 2004 11:24 am; edited 2 times in total
Back to top View user's profile Send private message Visit poster's website
admin
Site Admin


Joined: 03 Mar 2002
Posts: 1332

PostPosted: Sat Nov 20, 2004 10:04 am    Post subject: Reply with quote

Try this:

Code:
<html>
<body bgcolor="black">
<?
$dj = "hits.txt";
$fp = fopen($dj,"rb");
$kj = trim(fread($fp,filesize($dj)));
if ($kj != "") $kj++;
else $kj = 1;
@fclose($fp);
$fp = fopen($dj,"w");
@fputs($fp,$kj);

$kj = sprintf("%04d", intval($kj));

for($x=0;$x<strlen($kj);$x++) {
$img2 = substr($kj,$x,1);
$count = "<img src='images/$img2.gif'>";
}
@fclose($fp);
echo $count;
  ?>
</body>
</html>
Back to top View user's profile Send private message
PsychoticLucky7
-


Joined: 18 Aug 2004
Posts: 15

PostPosted: Sat Nov 20, 2004 5:50 pm    Post subject: Reply with quote

admin wrote:
Try this:


thanks for all of your help,I couldn't appreciate it more, but that code produced the same result as my original.

I think I'll just give it up,
Thanks Guys...

-PsychoticLucky7
_________________
InSaNiTy Is A gIfT!
Back to top View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group