Ver Mensaje Individual
  #9 (permalink)  
Antiguo 19/09/2013, 11:49
webankenovi
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: $_SERVER: PHP_SELF vs. REQUEST_URI

voy a intentar ayudar un poquito , podrias implementar un token que hara algo mas seguro la verificacion , te realize un ejemplo

un_archivo_cualquiera.php
Código PHP:
Ver original
  1.  
  2. $rand= rand(); // salt aleatorio pongo de ejemplo rand()
  3.  
  4. // funciona con las 2 cadenas
  5. $pagina = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
  6. // $p = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
  7.  
  8. // creamos el token , puedes generar el token como mas te guste yo puse este ejemplo
  9. // concatenamos el salt con la url y generamos un hash
  10. $hash = hash('whirlpool',$rand.$pagina);
  11.  
  12. // creamos la session para su postrior verificacion con el hash
  13. $_SESSION['TOKEN'] = $hash;
  14.  
  15. // creamos la session para guardar la url para su posterior verificacion
  16. $_SESSION['REFERER'] = $pagina;
  17.  
  18. // creamos la cookie para crear el hash en control y verificar
  19. setcookie('TOKEN',$rand);

control.php

Código PHP:
Ver original
  1.  
  2. // capturamos la url de donde vino
  3. $url = $_SERVER["HTTP_REFERER"];
  4. // $p = str_replace("http://", "", $_SERVER["HTTP_REFERER"]);
  5.  
  6. // comprobamos que existan todas las variables
  7. if(isset($_SESSION['TOKEN']) and isset($_SESSION['REFERER']) and isset($_COOKIE['TOKEN']))
  8. {
  9.     // creamos el hash
  10.     $hash = hash('whirlpool',$_COOKIE['TOKEN'].$url);
  11.  
  12.     // verificamos ambos hash y ambos referer
  13.     if($_SESSION['TOKEN'] === $hash and $_SESSION['REFERER'] === $url)
  14.     {
  15.  
  16.         // continuamos
  17.         echo 'correcto';
  18.     }
  19. }
  20.  
  21. // eliminamos los datos
  22. unset($_COOKIE['TOKEN'],$_SESSION['TOKEN'],$_SESSION['REFERER']);

ay puntos que debes de reforzar tan solo es un ejemplo , por ejemplo los nombres que no sean tan comunes y la cookie intentar mandarlo codificada o encriptada estaria muy bien, un buen salt aleatorio ,un buen hashing etc...

saludos