Tema: Que falla?
Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/12/2004, 11:01
Avatar de baklao
baklao
 
Fecha de Ingreso: noviembre-2004
Ubicación: Santa Ana - Isla de Margarita
Mensajes: 482
Antigüedad: 19 años, 5 meses
Puntos: 0
Hola aqui te mando un ejemplo a ver si lo puedes adaptar a tus necesidades:
Código PHP:
 <?php
class Usuariosenlinea
{
/*
    * @param string $servidor el host para conectar, usualmente localhost
    * @param string $basededatos el nombre de la base de datos
    * @param string $nombredb el nombre de la tabla, preferentemente no editar
    * @param string $usuario usuario de la base de datos
    * @param string $pass la contraseña de la base de datos
*/

   
var $servidor ''
   var 
$basededatos '';
   var 
$nombredb '';
   var 
$usuario '';
   var 
$pass '';
  
## Fin de Conexion ##

  
var $e_rror;
  
//Segundos para borrar de la base de datos a los usuarios inactivos
  
var $segundos 120;
  var 
$ahora 0;

    
//CONSTRUCTOR
    
function Usuariosenlinea() {

    
$this->recargar();

    }

    function 
cuantos() {

    return 
$this->ahora;

    }

    function 
enlinea() {

        if(
$this->ahora == 1) {

    echo 
$this->ahora;
        }
        else
        {
    echo 
$this->ahora;
        }

    }

        function 
ipreal(){

            if (
$real_ip getenv('HTTP_X_FORWARDED_FOR')){

                
$explode_real_ip explode(","$real_ip);
                return 
trim($explode_real_ip[0]);
            }
            else
            {
            return 
getenv('REMOTE_ADDR');
            }
        }

        function 
error(){

        return 
$this->e_rror mysql_error();

        }

        function 
recargar() {

            
$tiempo_actual time();
            
$tiempo_final $tiempo_actual $this->segundos;
            
$ip $this->ipreal();

        @
mysql_connect($this->servidor$this->usuario$this->pass)
        or die(
'Error al Intentar Conectar con la base de datos '.$this->error().'');

        @
mysql_select_db($this->basededatos)
        or die(
'Error Seleccionando la base de datos '.$this->error().'');

        
$result mysql_query("SELECT ip FROM $this->nombredb WHERE ip='$ip'")
        or die(
'Error de lectura en la base de datos '.$this->error().'');

        if(
mysql_num_rows($result) == 0){

//aqui deberias poner para insertar tu ip que de hecho ya lo hace en la tabla
        
mysql_query("INSERT INTO $this->nombredb VALUES ('$tiempo_actual','$ip','$_SERVER[REQUEST_URI]')")
        or die(
'Error al Insertar en la base de datos '.$this->error().'');

        }
        else

        {
// aqui pondrias tu echo de ya has votado
        
mysql_query("UPDATE $this->nombredb SET timestamp='$tiempo_actual' where ip='$ip'")
        or die(
'Error al Insertar en la base de datos '.$this->error().'');
        }
        
mysql_close();

        }

}

?>
Salu2. y suerte

Bye
__________________
Atte. Mohamed :aplauso: