Páginas: [1]
  Imprimir  
Autor Tema: restringir el acceso a un archivo en un sitio web  (Leído 114 veces)
0 Usuarios y 1 Visitante están viendo este tema.
H4CK-4-LIFE
Recién llegado
*

Karma: +0/-0
Mensajes: 3



Ver Perfil WWW Email
« : Julio 27, 2010, 06:18:45 »


hola saludos XD  espero me puedan ayudar,estoy haciendo una tienda online y quiero restringir un area para que el usuario no pueda entrar sin antes logearse,ya estube leyendo que se hace con cookies y sessiones,pero andaba vagando y me encontre con este script me podrian decir como implementarlo para que cuando quiera acceder le deniegue el acceso al visitante saludos XDs  
Código:
<?php
$archivo = '/unArchvio.gif';
 
if ( !isset ( $_SERVER['PHP_AUTH_USER'])) {
	header('WWW-Authenticate: Basic realm="My Realm"');
	header('HTTP/1.0 401 Unauthorized');
	echo 'Necesitas identificarte para continuar';
	exit;
} else {
	//Aquí validad usuario: $_SERVER[ 'PHP_AUTH_USER' ]
	//y password: $_SERVER[ 'PHP_AUTH_PW' ]
	//con tus validaciones preferidas y descargas el archivo
	if ( file_exists ( $archivo ) )
	{
		header ( 'Content-Description: Tranferencia de archivo' );
		header ( 'Content-Type: application/octet-stream');
		header ( 'Content-Disposition: attachment; filename='.basename($archivo));
		header ( 'Content-Transfer-Encoding: binary');
		header ( 'Expires: 0');
		header ( 'Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header ( 'Pragma: public');
		header ( 'Content-Length: ' . filesize($archivo));
		ob_clean ();
		flush ();
		readfile ( $archivo );
		exit;
	}
}
?>
 
En línea
nakp
Moderador global
Usuario regular
*****

Karma: +5/-1
Mensajes: 91



Ver Perfil
« Respuesta #1 : Julio 30, 2010, 01:15:10 »


En línea
Awes0mn
Recién llegado
*

Karma: +1/-0
Mensajes: 8


Ver Perfil Email
« Respuesta #2 : Julio 31, 2010, 06:29:23 »


¿Algo como un login? yo tengo uno en php*sin-mysql* te lo dejo,tal vez busques algo como...
Código:
<?php
/**********************
LOGIN.PHP
***********************/
 
//este es el usuario/s
 
#1
$adminuser = "user1";
$adminpass = "prueba";
#2
$adminuser = "user2";
$adminpass = "prueba";
 
//puedes agregar muchos
 
//Datos del Login.PHP
function loginpage($error) {
	echo "<html>\n<head>\n<title>Zona Privada - Login</title>\n";
	echo "</head>\n<body>\n";
	echo "<table style='width:100%;height:100%;'>\n<tr>\n<td align='center'>\n";
	echo "<form action='" . $_SERVER['REQUEST_URI'] . "' method='post'>\n";
        echo "<img src=/img/logo-emergeblogging.png>";
	echo "<table border='1' width='300' cellspacing='0' cellpadding='4'><tr>\n";
	$formtitle = "Zona Privada! - Por favor,Login.";
	if($error) $formtitle = "Wrong credentials!";
	echo "<th colspan='2'>" . $formtitle . "</th>\n";
	echo "</tr><tr>\n";
	echo "<td><p><b><label for='username'>Usuario:</label></b></p></td>\n";
	echo "<td><input type='text' name='username' id='username' size='30'></td>\n";
	echo "</tr><tr>\n";
	echo "<td><p><b><label for='password'>Contrase&ntilde;a:</label></b></p></td>\n";
	echo "<td><input type='password' name='password' id='password' size='30'></td>\n";
	echo "</tr><tr>\n";
	echo "<td><b>Login:</b></td>\n";
	echo "<td><input type='submit' value=' Entrar &raquo; ' name='login'></td></tr></table></form>\n";
	echo "</td>\n</tr>\n</table>\n</body>\n</html>";
	exit;
}
 
$username = $_POST['username'];
$password = $_POST['password'];
$login    = $_POST['login'];
 
session_start();
if($_SERVER['QUERY_STRING'] == "logout") {
	unset($_SESSION['authuser']);
	header("Location: " . $_SERVER['PHP_SELF']);
	exit;
}
if($_SESSION['authuser'] != $adminuser) {
	if(!$login) {
		loginpage(false);
	}
	elseif(($username != $adminuser) || ($password != $adminpass)) {
		loginpage(true);
	}
	else {
		$_SESSION['authuser'] = $adminuser;
		header("Location: " . $_SERVER['REQUEST_URI']);
	}
}
//Login
session_write_close();
?>
 
añade en por eje "privado.php"
Código:
<?php
require_once("login.php");
 
$authuser = $_SESSION['authuser'];
?>
En línea
Páginas: [1]
  Imprimir  
 
Ir a: