Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/06/2013, 17:15
keygen20
 
Fecha de Ingreso: noviembre-2008
Mensajes: 150
Antigüedad: 17 años, 11 meses
Puntos: 1
Pregunta Error Strict Standards En Clase Constructor y Undifined Index

muy buenas tardes amigo. una pregunta para expertos en PHP POO
sobre este sistemita de login que encontre en internet y hay problema cuando lo corre en mi servidor.

el error que me sale cuando el index. quiere acceder a la clase login.php



y sale errores en las lineas.. del archivo LOGIN.PHP

Código PHP:
<?PHP
if (version_compare(PHP_VERSION, '5.0.0') < 0)
{
    die(
'The CodeFlyer Framework requires PHP 5.x.x or greater.');
}


class 
login
{
    private 
$username;
    private 
$password;
    private 
$privilege;

    private 
$link;
    private 
$id;
    private 
$table;
    
    public 
$error;

  public function 
get($var)
  {
    
$var = trim(lcase($var));

    if (
$var=='privilege')
    {
      
$ret = $this->privilege;
    }
    else if (
$var=='username')
    {
      
$ret = $this->username;
    }
    else if (
$var=='password')
    {
      
$ret = $this->password;
    }
    else
    {
      
$ret = false;
    }
    return 
$ret;
  }

  public function 
isadmin()
    {
    return 
$this->privilege == 1;
    }
  public function 
isJefe()
    {
    return 
$this->privilege == 2;
    }        
  public function 
isEmpleado()
    {
    return 
$this->privilege == 3;
    }
    
//privilegios
    
    
public function getdata($data)
    {
    
$data = $this->clean(trim($data));
    
$query = "SELECT $data FROM {$this->table} WHERE id='{$this->id}' LIMIT 1;";
    if (
$result = mysql_query($query, $this->link))
    {
      if (
$row = mysql_fetch_assoc($result))
      {
        return 
$row[$data];
      }
    }
    }

    public function 
modlastlogin()
    {
        
mysql_query("UPDATE {$this->table} SET lastactive = NOW() WHERE id = '{$this->id}';", $this->link);
        return 
mysql_affected_rows($this->link)==1 ? true : false;
    }

    public function 
lastlogin()
    {
        if (
$result = mysql_query("SELECT lastactive FROM {$this->table} WHERE id = '{$this->id}' LIMIT 1", $this->link))
        {
            if (
$row = mysql_fetch_assoc($result))
            {
                return 
$row['lastactive'];
            }
        }
    }

    
/**
     * Login core
     */
    
public function inherit($session)
    {
    
session_name(urldecode($session));
    }

    public function 
getSID()
    {
    return 
"PHPSESSID=".session_id();
    }

  public function 
login($username, $password, $remember = false)
  {
    
$username = $this->clean($username);
    
$password = md5($password);
    
$query    = "SELECT * FROM {$this->table} WHERE username = '$username' LIMIT 1;";

    if (
$result = mysql_query($query, $this->link))
    {
      if (
$row = mysql_fetch_assoc($result))
      {
        if (
$row['password']==$password)
        {
          return 
$this->setSession($row, $remember);
        }
        else
        {
          
$this->logout();
          
$this->error = 'pi'; // Password Incorrect
          
return false;
        }
      }
      
$this->logout();
      
$this->error = 'ui'; // Username Incorrect
      
return false;
    }
    else
    {
      
$this->logout();
      return 
false;
    }
  }
  
  
// Construir la session y la cookie, y guardarlas en la base de datos.
  
private function setSession(&$values, $remember = false, $init = true)
  {
    
$this->id         = $values['id'];
    
$this->username   = $values['username'];
    
$this->password   = $values['password'];
    
$this->privilege  = $values['privilege'];

    
$_SESSION['cf_login_username'] = htmlspecialchars($this->username);
    
$_SESSION['ID'] = $this->id;
    
$_SESSION['Nivel'] = $this->privilege;
    
$cookie = md5($values['username'].date("Y-m-d"));
    if (
$remember)
    {
      
$this->update_cookie($cookie, true);
    }

    if (
$init)
    {
      
$session = session_id();
      
mysql_query("UPDATE {$this->table} SET session='{$session}', cookie='{$cookie}' WHERE id='{$this->id}'", $this->link);
      
$this->modlastlogin();
    }
    return 
true;
  }

  private function 
update_cookie($cookie)
  {
    
$this->create_cookie('cf_login_cookie', serialize(array($this->username, $this->password, $cookie)), time() + 31104000);
  }
  
  public function 
create_cookie($name, $value='', $maxage=0, $domain='', $path='', $secure=false, $HTTPOnly=false)
  {
    
$ob = ini_get('output_buffering');
    
    if (
$_SERVER['HTTPS'])
    {
      
$secure = true;
    }

    
// Abort the method if headers have already been sent, except when output buffering has been enabled
    
if ( headers_sent() && (bool) $ob === false || strtolower($ob) == 'off' )
    {
      return 
false;
    }

    if (!(bool)
$maxage)
    {
      
$maxage = time()+3600;
    }

    if ( !empty(
$domain) )
    {
      
// Fix the domain to accept domains with and without 'www.'.
      
if ( strtolower( substr($domain, 0, 4) ) == 'www.' )
      {
        
$domain = substr($domain, 4);
      }

      
// Add the dot prefix to ensure compatibility with subdomains
      
if ( substr($domain, 0, 1) != '.' )
      {
        
$domain = '.'.$domain;
      }


      
// Remove port information.
      
$port = strpos($domain, ':');

      if ( 
$port !== false )
      {
        
$domain = substr($domain, 0, $port);
      }
    }
    else
    {
      
// Localhost compatibility
      
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
    }

    
header('Set-Cookie: ' .rawurlencode($name).'='.rawurlencode($value)
                          .(empty(
$domain) ? '' : '; Domain='.$domain )
                          .(empty(
$maxage) ? '' : '; Max-Age='.$maxage)
                          .(empty(
$path)   ? '' : '; Path='.$path     )
                          .(!
$secure       ? '' : '; Secure'          )
                          .(!
$HTTPOnly     ? '' : '; HttpOnly'        )
          , 
false);
    return 
true;
  }

  
// Devuelve true si el usuario está logueado. Caso contrario devuelve false.
  // @return bool
    
public function logged()
    {

    
$cookie = array();
    if (
$_COOKIE['cf_login_cookie'])
    {
      list(
$cookie['username'], $cookie['password'], $cookie['serial']) = @unserialize(stripslashes($_COOKIE['cf_login_cookie']));
    }

    if (
$cookie['serial'] && $cookie['username'] && $cookie['password'])
    {
      
$query    = "SELECT * FROM {$this->table} WHERE (username = '{$cookie['username']}') AND (password = '{$cookie['password']}') AND (cookie = '{$cookie['serial']}') LIMIT 1;";
    }
    else
    {
      
// Verificar si los datos de session son válidos.
      
$username = $_SESSION['cf_login_username'];
      
$session  = session_id();
      
$query    = "SELECT * FROM {$this->table} WHERE (username = '$username') AND (session = '$session') LIMIT 1;";
    }


    if (
$result = mysql_query($query, $this->link))
    {
      if (
$row = mysql_fetch_assoc($result))
      {
        return 
$this->setSession($row, false, false); // Log in
      
}
      else
      {
        return 
false;
      }
    }
    else
    {
      return 
false;
    }
    }

    public function 
logout()
    {
    
$_SESSION['cf_login_username'] = '';
    
$_SESSION['cf_login_cookie']   = 0;
    
$this->create_cookie('cf_login_cookie', '', time() - 3600);
    
mysql_query("UPDATE {$this->table} SET session='".strtoupper(md5(time()))."', cookie='".strtoupper(md5(time()))."' WHERE id='{$this->id}'", $this->link);

    
$this->username = '';
    
$this->password = '';
    
$this->privilege = 0;
    
$this->id = 0;
  }

  private function 
clean($value)
  {
    if (
get_magic_quotes_gpc())
    {
      
$value = stripslashes($value);
    }
    
$value = mysql_real_escape_string( htmlspecialchars( $value ) );
    return 
$value;
  }

    public function 
__construct($array)
    {
    
$this->table = $array['table'] ? $array['table'] : 'login';
    
$this->link  = mysql_connect( $array['host'] ? $array['host'] : 'localhost', $array['username'], $array['password'], true );
    if (!
$this->link)
    {
      die(
mysql_error());
    }
    else
    {
      if (!
mysql_select_db($array['database']))
      {
        die(
mysql_error());
      }
    }

    if (isset(
$_GET['PHPSESSID']))
    {
      
session_id($_GET['PHPSESSID']);
    }

    
session_start();
    }

}

?>
y me sale ese error y no me funciona el sistema de login
esta corrido en xampp
ojo este sistema de logeo me funcionaba en appserver
pero en xampp no me funciona porfavor

el error en la linea 302 y 305 aparece aqui.

Código PHP:
public function __construct($array)
    {
    
$this->table = $array['table'] ? $array['table'] : 'login';
    
$this->link  = mysql_connect( $array['host'] ? $array['host'] : 'localhost', $array['username'], $array['password'], true );
    if (!
$this->link)
    {
      die(
mysql_error());
    }
    else
    {
      if (!
mysql_select_db($array['database']))
      {
        die(
mysql_error());
      }
    }

    if (isset(
$_GET['PHPSESSID']))
    {
      
session_id($_GET['PHPSESSID']);
    }

    
session_start();
    } 
el error en la linea 236 y 242 aqui.

Código PHP:
$cookie = array();
    if (
$_COOKIE['cf_login_cookie'])
    {
      list(
$cookie['username'], $cookie['password'], $cookie['serial']) = @unserialize(stripslashes($_COOKIE['cf_login_cookie']));
    }
  
    
// Verificar si los datos de la cookie son válidos.
    
if ($cookie['serial'] && $cookie['username'] && $cookie['password'])
    {
      
$query    = "SELECT * FROM {$this->table} WHERE (username = '{$cookie['username']}') AND (password = '{$cookie['password']}') AND (cookie = '{$cookie['serial']}') LIMIT 1;";
    } 
porfavor me podrian decir que sucede o como solucionarlo de antemano muchas gracias!