Help on PHP counter on an html page...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello Everyone.

Im trying to make a counter in my server BUT I would like to call it FROM

Let me explain this a little further:

Suppose I have a PHP-IIS Server working properly with an script called
counter.php. Well call this server NUMBER ONE

I want to show the counter on an HTML page that is hosted ON ANOTHER SERVER,
not mine. (I can upload the html though). Well call this server NUMBER TWO.

Now, I created an html page called default.htm calling the script using:

  <script language="JavaScript1.2" type="text/javascript"
src="www.NUMBERONE.COM/counter.php"> </script>

And I stored the HTML file on the NUMBER TWO server.

Now, I want to open the url http://WWW.NUMBERTWO.COM/default.htm and I want
it to show the IMAGES from MY counter ON NUMBER ONE!

Now, the problem Im having is that the counter INCREMENTS ITSELF when I

If I open HTTP://WWW.NUMBERONE.COM/COUNTER.PHP it shows all the images

Now, Im a Newbie and I have no clue of what is going on here... Can anyone
help me???

I dont know if the problem is in my html file or in my php script...



include ("parameters.inf");
$vdigits = 1;
if (file_exists("$datafile")) {
 $fp = fopen("$datafile", "r+");
 flock($fp, 2);
 $count = fgets($fp, 4096);
 $count += 1;
 fwrite($fp, $count);
 flock($fp, 3);
} else {
 echo "Your Counter.dat file is missing '$file' var...<BR>";

$vdigits = max(strlen($count), $vdigits);

$count = substr("0000000000".$count, -$vdigits);

$varreglo = preg_split("//", $count);

for($i = 0; $i <= $vdigits; $i++) {
 if ($varreglo[$i] != "") {
  echo "<IMG SRC=\"$imgdir$varreglo[$i].gif\" border=\"0\"

Re: Help on PHP counter on an html page...

On Thu, 10 Jul 2003 21:55:03 -0400, "Balbino Brito"

Quoted text here. Click to load it

But your PHP script doesn't output any javascript, so that will not

If you really want to do a PHP counter, you should use PHP's imaging
functions to output an image. Then you "call" it thus:

<img src=' '>

Although you're better getting a stats package from your host.

Remember that PHP is executed entirely server-side, so all you can
ever use is the output from the scripts.

David (please modify address to david@ before replying!)

Re: Help on PHP counter on an html page...

Hello en|ckma

Im sorry, but at the beginning of my code theres a line that reads:

include ("counter.inf");

Into that file I have the following definitions:

<? $imgdir = "http://www.NUMBERONE.COM/images/counter /";
$datafile = "c:\inetpub\www\counter\counter.dat";
$digits = "5"; ?>

So, the script was done the way you are saying. Nice try anyway and thank
you for your post.

Any other ideas?

Thanks in advance

Quoted text here. Click to load it

Re: Help on PHP counter on an html page...

Hello Everyone.

I tried changing COMPLETELY the script to do just one thing:

File counter.php installed on
$result="<IMG SRC=";
$result .='"';
$result .="";
$result .='">';

echo $result;

File countertest.htm installed on
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body bgcolor="#FFFFFF" text="#000000">
<p>&nbsp; </p>
<script language="php" src=" "> </script>

Now, when I call from my web browser http://www.NUMBERONE.COM/counter.php it
returns a nice little number 1 with a flag behind it. I mean, the .gif file.
I can see it...

Now, when I call from my web browser
http://www.NUMBERTWO.COM/countertest.htm it doesnt show anything at all.

So theres my problem. How can I send the correct text to the browser FROM
the php file called through SCRIPT in an HTML page.

At least now I know that the problem its not the script itself, its
something different.... I dont know what it is....

Help me please!!!!

Thanks a lot in advance.


Re: Help on PHP counter on an html page...

Balbino Brito wrote:

Quoted text here. Click to load it
You simply can't do that.  Try using an iframe (<iframe
src=" "></iframe>) or making
counter.php use GD ( and showing it with an img tag.

Site Timeline