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:
  
check.php<?php
/**
 * @author mauri
 * @copyright 2011
 */
include_once ("vAuthenticate/auth.php");
include_once ("vAuthenticate/authconfig.php");
include_once ("vAuthenticate/check.php");
session_start();
Código:
  
Auth.php<?
    // 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;
    }
Código:
  
La cookie se crea cuando uno se loguea:// 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
vAuthenticate.php
Código:
  
Por ultimo dejo el codigo de la web a la cual si se puede acceder, es decir las cookies son reconocidas.// 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);
	
?>
index.php
Código:
  
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.<?
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>
Gracias saludos
 

