He tomado el siguiente codigo:
Código PHP:
   <?
//Script created by Razore.co.uk under the GNU GPL
 
 
//Database variables
$server             = "localhost";          // Your MySQL Server address. This is usually localhost
$db_user            = "nombre_username";         // Your MySQL Username
$db_pass            = "pass_username";        // Your MySQL Password
$database           = "nombre_BD";          // Database Name
 
//Customizations
$timeoutseconds     = "300";            // How long it it boefore the user is no longer online
$showlink         = "0";                  // Link to us? 1 = Yes  0 = No
 
//Only one person is online
$oneperson1       = "En la actualidad hay";  //Change the text that will be displayed
$oneperson2       = "usuario online.";     //Change the text that will be displayed
 
//Two or more people online
$twopeople1       ="En la actualidad hay"; //Change the text that will be displayed
$twopeople2       ="usuarios online.";      //Change the text that will be displayed
 
//The following should only be modified if you know what you are doing
$timestamp=time();
$timeout=$timestamp-$timeoutseconds;  
mysql_connect($server, $db_user, $db_pass) or die ("online Database CONNECT Error");                                                                   
mysql_db_query($database, "INSERT INTO online VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')") or die("online Database INSERT Error"); 
mysql_db_query($database, "DELETE FROM online WHERE timestamp<$timeout") or die("online Database DELETE Error");
$result=mysql_db_query($database, "SELECT DISTINCT ip FROM online WHERE file='$PHP_SELF'") or die("online Database SELECT Error");
$user  =mysql_num_rows($result);
mysql_close();
 
 
if ($user==1) {$archivo = 'archivo.txt';
$fp = fopen($archivo, "w");
$string = "$oneperson1 $user $oneperson2";
$write = fputs($fp, $string);
fclose($fp);}
 
else {$archivo = 'archivo.txt';
$fp = fopen($archivo, "w");
$string = "$twopeople1 $user $twopeople2";
$write = fputs($fp, $string);
fclose($fp);}
 
//If you have chosen to support us.
switch ($showlink) {
case 0:
   echo "";
   break;
case 1:
   echo "<br><br><font size=\"1\">Prueba Design Online by
<a target=\"_blank\" href=\"pagina aqui\">Prueba</a></font>";
   break;
}
?>    
Código:
  
Este es el codigo del contador y el de la BD.#Created by Razore # # Table structure for table 'online' # CREATE TABLE online ( timestamp int(15) DEFAULT '0' NOT NULL, ip varchar(40) NOT NULL, file varchar(100) NOT NULL, PRIMARY KEY (timestamp), KEY ip (ip), KEY file (file) );
Bien explico el código php, se conecta a la base de datos y va agregando usuarios ("visitantes") a la tabla, se borrára despues de que haya consumado su secion 300seg, y la cadena de los valores de las variables es guardada en el archivo.txt
Ahora en la pagina del chat he colocado
Código PHP:
   <?php
//This file shows you how to include the file in your php document.
include("online.php"); 
?>    Ahora hize otro archivo php, donde genera una imagen leyendo el texto que se encuentra en el archivo.txt y coloque esa imagen en cualquier parte de mi sitio web y muestre los visitantes que estan en la pagina custom del foro (que viene siendo la del chat)
el codigo es el siguiente:
Código PHP:
   <?php
$archivo = 'archivo.txt';
$fp = fopen($archivo, "r");
$contents = fread($fp, filesize($archivo));
 
$font = imageloadfont('8x13iso.gdf');
 
/* I use .gdf as its extension to represents "GD Fonts" */
/* But, if your server not allow .gdf, you can change it*/
/* to any extension .jpg, .bmp, .txt, .bmf, .etc        */
 
$fontWidth = imagefontwidth($font);
$fontHeight = imagefontheight($font);
$im = imagecreate(strlen($contents) * $fontWidth, $fontHeight);
$bgColor = imagecolorallocate($im, 255, 255, 255);
$fgColor = imagecolorallocate($im,   0,   0, 255);
imagestring($im, $font, 0, 0, $contents, $fgColor);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
fclose($fp);
?>    Ahora las siguientes cuestiones que me complican es como puedo actualizar la base de datos de la tabla online cuando no haya visitantes dentro de la pagina del chat y asi escriba en el archivo.txt que "Hay 0 usuarios en linea"
Cabe aclarar que va agregando los datos a la tabla y al terminar su secion va borrando los datos en la BD pero no borra la ultima secion y se queda guardada.
La verdad no se si me complique la vida, pero no quiero usar un contador gratuito.
Solo quiero mostrar el # de visitantes que estan "en este tiempo en linea" en la pagina del chat y mostrarlo en otras paginas sin aumentar el contador.
Espero y me ayuden a resolver algo, agrego que no soy muy experto en PHP pero he estado leyendo las funciones y eso ahora si que me declaró un novato.
 
 
 Contador de visitas Online
 Contador de visitas Online 
 ??? (de esta forma tendrías que usar include para poder usarlo)
??? (de esta forma tendrías que usar include para poder usarlo)
