Help on PHP counter on an html page...

B

Balbino Brito

Hello Everyone.

I´m trying to make a counter in my server BUT I would like to call it FROM
ANOTHER SERVER.

Let me explain this a little further:

Suppose I have a PHP-IIS Server working properly with an script called
counter.php. We´ll 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). We´ll call this server NUMBER TWO.

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

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

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 I´m having is that the counter INCREMENTS ITSELF when I
open the page, BUT IT DOESN´T SHOW THE IMAGES...

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

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

I don´t know if the problem is in my html file or in my php script...

Help!!!

BB

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

$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\"
alt=\"$varreglo[$i]\">";
}
}
?>
 
D

David Mackenzie

Hello Everyone.

I´m trying to make a counter in my server BUT I would like to call it FROM
ANOTHER SERVER.

Let me explain this a little further:

Suppose I have a PHP-IIS Server working properly with an script called
counter.php. We´ll 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). We´ll call this server NUMBER TWO.

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

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

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

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='http://www.example.com/counter.php'>

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.
 
B

Balbino Brito

Hello en|ckma

I´m sorry, but at the beginning of my code there´s 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


e n | c k m a said:
Balbino Brito said:
for($i = 0; $i <= $vdigits; $i++) {
if ($varreglo[$i] != "") {
echo "<IMG SRC=\"$imgdir$varreglo[$i].gif\" border=\"0\"
alt=\"$varreglo[$i]\">";
}
}
?>

I'm not 100% on this but it could be because it's looking for the images
locally rather than on the remote server. Try something like:

echo "<IMG SRC=\http://www.imgserver.com/$imgdir$varreglo[$i].gif\
border=\"0\"

or something... worth a go.

Nick.
 
B

Balbino Brito

Hello Everyone.

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

File counter.php installed on www.numberone.com
<?php
$result="<IMG SRC=";
$result .='"';
$result .="http://www.NUMBERONE.com/images/counter/1.gif";
$result .='">';

echo $result;
?>

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

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 doesn´t show anything at all.

So there´s 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 it´s not the script itself, it´s
something different.... I don´t know what it is....

Help me please!!!!

Thanks a lot in advance.

BB
 
L

Leif K-Brooks

Balbino said:
Sorry to hear that, but i found some other things that make me believe that
you are confused somehow.
Or that I don't like mixing content with presentation.
I searched for reference on the Iframe command and I found that I can use
these additional parameters...

FRAMEBORDER=YES/NO
WIDTH
HEIGHT

and others...
Those are for presentation, which isn't what HTML is about. They're
also deprecated.
I tried those parameters and IE did the rendering... Now, I think that yours
could be a solution, but I know there must be a way to do it through PHP and
using the script... If you want a proof try using the free counter from
www.bravenet.com and see the code they tell you to put in your page... It´s
a PHP script and it´s called from the html using /script. Now, i don´t know
what they are doing to send the url fine.
They have a PHP script outputting javascript.
 
B

Balbino Brito

Hello Leif. Thanks a lot for your help on this matter!!!

I did it using your suggestion and adding the additional parameters... I´m
barely starting with php to start learning php and javascript integration.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top