Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/07/2005, 13:58
Avatar de turco_7
turco_7
 
Fecha de Ingreso: diciembre-2003
Ubicación: Córdoba, Argentina
Mensajes: 1.044
Antigüedad: 20 años, 4 meses
Puntos: 19
Index :

Código HTML:
<form action="control.php" method="POST">

	<table align="center" border=1 bordercolor="black" cellspacing="0">
	<tr>
	<td>
		<table border=0 align="center" cellspacing=0 width="350"> 
		<tr><td bgcolor="white">
			<table align="center" bgcolor="white">
				<tr><td><img src="images/llave.jpg"></td></tr>
				<tr>
			</table>
		</td>
		<td bgcolor="white">
			<table align="center" border=0 cellSpacing=0>
				<td align="center" width="200"
				<?if ($_GET["errorusuario"]=="si"){?>
					bgcolor=red><span style="color:ffffff"><b>Datos incorrectos</b></span>
				<?}else{?>
					bgColor=#cdcec1>Introduce tu clave de acceso
				<?}?>
				</td>
				</tr>
				<tr>
				<td align="center" bgColor="#cdcec1">
				<input type="text" name="usuario" size="10" maxlength="50"><br>
				<input type="password" name="clave" size="10" maxlength="50"><br>
				<input type="submit" value="LOGIN">
				</td>
				</tr>
				<tr>
				<td><font face="verdana" size=1><a href="recuperar.php">Olvido su contraseña?</a></font></td>	
				</tr>
				
			</table>
		</td>
		</tr>
		</table>
	</td>
	</tr>
	</table>
</form> 
Archivo control

Código PHP:
<?
include ("conectar.php");

if (
$_POST["usuario"]!="" && $_POST["clave"]!=""){
    
$usuario $_POST["usuario"];
    
$clave $_POST["clave"];
    
$sql "SELECT * FROM usuarios where usuario='$usuario' and clave='$clave'";
    
$res mysql_query($sql) or die("Error en la consult SQL: " mysql_error());
    if(
mysql_num_rows($res) > 0){
        
//session_start();
        
$_SESSION["autentificado"]= "SI";
        print 
"<meta http-equiv=Refresh content=\"3 ; url=panel.php\">"
    }else{
        print 
"<meta http-equiv=Refresh content=\"3 ; url=index.php?errorusuario=si\">";
    }
}
include (
"desconectar.php");
?>
En la cabecera de cada archivo que quiero proteger pongo esto

Código PHP:
<?include ("seguridad.php");?>
seguridad.php

Código PHP:
<?
//Inicio la sesión
session_start();

//COMPRUEBA QUE EL USUARIO ESTA AUTENTIFICADO
if ($_SESSION["autentificado"] != "SI") {
    
//si no existe, envio a la página de autentificacion
    
header("Location: index.php");
    
//ademas salgo de este script
    
exit();
}    
?>


A mi entender y al entender de varios este escript funciona correctamente y no se le puede inyectar codigo SQL ... por lo menos para es util ... y espero que te sea util ...
__________________
Mi Blog http://turco7.blogspot.com
Usuario Linux : 404289
Mi última página: http://www.digitalservicecba.com.ar - Reparacion de camaras digitales!