Foros del Web » Programando para Internet » PHP »

Problema con acceso usuarios (logueados)

Estas en el tema de Problema con acceso usuarios (logueados) en el foro de PHP en Foros del Web. Hola gente. Descargue un script php, para login de usuarios y autentificaciones mediante cookies y sesiones. El problema es que, una vez logueado el usuario ...
  #1 (permalink)  
Antiguo 03/04/2011, 15:32
 
Fecha de Ingreso: octubre-2008
Mensajes: 47
Antigüedad: 15 años, 7 meses
Puntos: 0
Problema con acceso usuarios (logueados)

Hola gente.
Descargue un script php, para login de usuarios y autentificaciones mediante cookies y sesiones.
El problema es que, una vez logueado el usuario puede ingresar a: members/index.php pero si intento por ejemplo a restringido.php, lo que falla es la comprobacion de existencia de cookie mediante isset.

Dejo el codigo:

restringir.php:

Código:
<?php
/**
 * @author mauri
 * @copyright 2011
 */


include_once ("vAuthenticate/auth.php");
include_once ("vAuthenticate/authconfig.php");
include_once ("vAuthenticate/check.php");
session_start();
check.php
Código:
<?
    // Check if the cookies are set
    // This removes some notices (undefined index)
    if (isset($_COOKIE["USERNAME"]) && isset($_COOKIE["PASSWORD"])) // ESTA ETAPA NO ES PASADA EN REGISTRAR.PHP PERO SI EN INDEX.PHP
    {

        // Get values from superglobal variables
        $USERNAME = $_COOKIE['USERNAME'];
        $PASSWORD = $_COOKIE['PASSWORD'];
        $CheckSecurity = new auth();
        $check = $CheckSecurity->page_check($USERNAME, $PASSWORD);
    }
    else
    {
        
$check = false;
    }
Auth.php
Código:
// PAGE CHECK
	// This function is the one used for every page that is to be secured. This is not the same one
	// used in the initial login screen
	function page_check($username, $password) {

echo "ultimo: ". $username;
		$query = "SELECT * FROM authuser WHERE uname='$username' AND passwd=MD5('$password') AND status <> 'inactive'";

        $connection = mysql_connect($this->HOST, $this->USERNAME, $this->PASSWORD);
		
		$SelectedDB = mysql_select_db($this->DBNAME);
		$result = mysql_query($query); 
		
		$numrows = mysql_num_rows($result);
		$row = mysql_fetch_array($result);

		// CHECK IF THERE ARE RESULTS
		// Logic: If the number of rows of the resulting recordset is 0, that means that no
		// match was found. Meaning, wrong username-password combination.
		if ($numrows == 0) {
			return false;
		}
		else {
			return $row;
		}
	} // End: function page_check
La cookie se crea cuando uno se loguea:

vAuthenticate.php
Código:
// Start Code

	// Use Sessions
	// NOTE: This will store the username and password entered by the user to the cookie
	// variables USERNAME and PASSWORD respectively even if the combination is correct or
	// not. Be sure to authenticate every page that you want to be secured and pass as 
	// parameters the variables USERNAME and PASSWORD.
	setcookie ("USERNAME", $_POST['username'],time()+60*60*24*30);
	setcookie ("PASSWORD", $_POST['password'],time()+60*60*24*30);
 
    // Change the path to auth.php and authconfig.php if you moved
    // vAuthenticate.php from its original directory.
  	include_once ("auth.php");
	include_once ("authconfig.php");
    $username =  $_POST['username'];
    $password =  $_POST['password'];
	$Auth = new auth();
	$detail = $Auth->authenticate($username, $password);
	
?>
Por ultimo dejo el codigo de la web a la cual si se puede acceder, es decir las cookies son reconocidas.

index.php
Código:
<?
include_once ("../auth.php");
include_once ("../authconfig.php");
include_once ("../check.php");
?>

<html>
<head>
<title>vAuthenticate Sample User Login Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
Realmente no se que pueda estar fallando, ya que los include son exactamente los mismos en uno y otro (exceptuando la ruta, que estan en distintos lugares), y a uno se puede acceder tranquilamente, y al otro no, no reconoce la existencia de mi cookie con el contenido de username y password.

Gracias saludos
  #2 (permalink)  
Antiguo 03/04/2011, 19:52
 
Fecha de Ingreso: octubre-2008
Mensajes: 47
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Problema con acceso usuarios (logueados)

Hecho, especifique la path de las cookies y listo :P

Etiquetas: usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:15.