Ver Mensaje Individual
  #42 (permalink)  
Antiguo 13/05/2010, 05:08
Avatar de Flow89
Flow89
 
Fecha de Ingreso: abril-2010
Ubicación: Valladolid
Mensajes: 346
Antigüedad: 14 años
Puntos: 1
Respuesta: Seguridad en PHP [Importante];

Sigamos con el tema de seguridad, ahora con el archivo ingresar.php

tenia este codigo;
Código PHP:
 <html>
<head>
<title>JuventudMDC - Panel de Administraci&oacute;n</title>
<link href="../css/general.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
   
include("conex.php");
   include(
"segu.php");


function 
quitar($mensaje)
   {
   
$mensaje str_replace("<","&lt;",$mensaje);
   
$mensaje str_replace(">","&gt;",$mensaje);
   
$mensaje str_replace("\'","'",$mensaje);
   
$mensaje str_replace('\"',"&quot;",$mensaje);
  
$mensaje str_replace("\\\\","\\",$mensaje);
  return 
$mensaje;
   }
  
  if(
trim($HTTP_POST_VARS["nick"]) != "" && trim($HTTP_POST_VARS["password"]) != "")
  {
  
$nickN quitar($HTTP_POST_VARS["nick"]);
  
$passN quitar($HTTP_POST_VARS["password"]);
  
$result mysql_query("SELECT password FROM usuarios WHERE nick='$nickN'");
  if(
$row mysql_fetch_array($result))
   {
  if(
$row["password"] == $passN)
  {
  
//La cookie dura 1 hora
  
setcookie("usNick",$nickN,time()+36000);
  
setcookie("usPass",$passN,time()+36000);
  echo 
"<table style=\"height:100%;width:100%;\" border=\"0\"><tr><td class=\"estilo34\"><div align=\"center\">Logueado correctamente, ahora sera dirigido a el panel de administración automaticamente.</div></td></tr></table>";
  echo 
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; url=administracion.php\">";
  }
  else
  {
  echo 
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; url=../panel.php\">";
  echo 
"<table style=\"height:100%;width:100%;\"border=\"0\"><tr><td class=\"estilo34\"><div align=\"center\"><br>Contraseña incorrecta. <br> Seras redireccionado automaticamente.</div></td></tr></table>";
  }
  }
  else
  {
  echo 
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; url=../panel.php\">";
  echo 
"<table style=\"height:100%;width:100%;\"border=\"0\"><tr><td class=\"estilo34\"><div align=\"center\"><br>Ese Usuario no existe en la base de datos. <br> Seras redireccionado automaticamente.</div></td></tr></table>";
  }
  
mysql_free_result($result);
  }
  else
  {
  echo 
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; url=../panel.php\">";
  echo 
"<table style=\"height:100%;width:100%;\"border=\"0\"><tr><td class=\"estilo34\"><div align=\"center\"><br>Debe especificar un nick y password. <br> Seras redireccionado automaticamente.</div></td></tr></table>";
  }
  
mysql_close();  
  
?> 
</body>
</html>

Que se ha convertido en este otro Este es el q hay que revisar, el otro funciona bien
Código PHP:
<html>
<head>
<title>JuventudMDC - Panel de Administraci&oacute;n</title>
<link href="../css/general.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
   
include("conex.php");
   include(
"segu.php");

$nick mysql_real_escape_string($HTTP_POST_VARS["nick"]);
$password mysql_real_escape_string($HTTP_POST_VARS["nick"]);

function 
quitar($mensaje)
   {
   
$mensaje str_replace("<","&lt;",$mensaje);
   
$mensaje str_replace(">","&gt;",$mensaje);
   
$mensaje str_replace("\'","'",$mensaje);
   
$mensaje str_replace('\"',"&quot;",$mensaje);
  
$mensaje str_replace("\\\\","\\",$mensaje);
  return 
$mensaje;
   }
  
  if(
trim("$nick") != "" && trim("$password") != "")
  {
$nickN my_real_escape_string($nickN);
$passN my_real_escape_string($passN);
  
$nickN quitar("$nick");
  
$passN quitar("$password");


  
$result mysql_query("SELECT password FROM usuarios WHERE nick='$nickN'");
  if(
$row mysql_fetch_array($result))
   {
  if(
$row["password"] == $passN)
  {
  
//La cookie dura 1 hora
  
setcookie("usNick",$nickN,time()+36000);
  
setcookie("usPass",$passN,time()+36000);
  echo 
"<table style=\"height:100%;width:100%;\" border=\"0\"><tr><td class=\"estilo34\"><div align=\"center\">Logueado correctamente, ahora sera dirigido a el panel de administración automaticamente.</div></td></tr></table>";
  echo 
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; url=administracion.php\">";
  }
  else
  {
  echo 
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; url=../panel.php\">";
  echo 
"<table style=\"height:100%;width:100%;\"border=\"0\"><tr><td class=\"estilo34\"><div align=\"center\"><br>Contraseña incorrecta. <br> Seras redireccionado automaticamente.</div></td></tr></table>";
  }
  }
  else
  {
  echo 
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; url=../panel.php\">";
  echo 
"<table style=\"height:100%;width:100%;\"border=\"0\"><tr><td class=\"estilo34\"><div align=\"center\"><br>Ese Usuario no existe en la base de datos. <br> Seras redireccionado automaticamente.</div></td></tr></table>";
  }
  
mysql_free_result($result);
  }
  else
  {
  echo 
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"2; url=../panel.php\">";
  echo 
"<table style=\"height:100%;width:100%;\"border=\"0\"><tr><td class=\"estilo34\"><div align=\"center\"><br>Debe especificar un nick y password. <br> Seras redireccionado automaticamente.</div></td></tr></table>";
  }
  
mysql_close();  
  
?> 
</body>
</html>

El caso es que, a raiz de poner el mysql_real_escape_string, debe modificar algo internamente y me dice que la contraseña es incorrecta. :S

Debería quitarlo? con el str_replace sería suficiente en este caso?

Como podría modificar el str_replace por el htmlentities? no entiendo muy bien como se usa.


Un saludo y Gracias