Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function codigo_valido($mi_code){
  5. if (is_numeric($mi_code) && $mi_code % 37 == 0)
  6. return true; # Es valido
  7. else
  8. return false; # No lo es
  9.  
  10. }
  11.  
  12. # Funcion imaginaria que comprueba las credenciales
  13. function comprueba_credenciales($usuario, $clave){
  14. return true;
  15. }
  16.  
  17. if (isset($_COOKIE['nombre_para_examen'])) {
  18. header('Location: inicio.php');
  19. }
  20.  
  21.  
  22.  
  23. if (isset($_POST['aceptar'])) {
  24. if ($_POST['invitado'] == "inv") {
  25. #echo "Invitado seleccionado";
  26. $comprueba_codigo = codigo_valido($_POST['codigo']);
  27. if ($comprueba_codigo) {
  28. $nombre=$_POST['usuario'];
  29.  
  30.  
  31. # Crear variable de sesión
  32. session_start();
  33. $_SESSION['nombre_para_examen']=$_POST['usuario'];
  34. $_SESSION['fecha']=date("D M d, Y G:i");
  35.  
  36. # Redirigir
  37. header('Location: inicio.php');
  38. }
  39. else
  40. {
  41. echo "No has introducido un codigo valido";
  42. }
  43.  
  44. }
  45. else
  46. {
  47. #echo "No es invitado";
  48. $credenciales=comprueba_credenciales("blabla", "blabla");
  49.  
  50. if ($credenciales) {
  51. # Creamos sesion
  52. session_start();
  53. $_SESSION['nombre_para_examen']=$_POST['usuario'];
  54. $_SESSION['fecha']=date("D M d, Y G:i");
  55.  
  56. # Creamos la Cookie
  57. setcookie('nombre_para_examen', $_POST['usuario'], time() + 86400);
  58.  
  59. # Redireccionamos
  60. header('Location: inicio.php');
  61.  
  62. }
  63. else
  64. {
  65. echo "Es imposible que se de este caso porque la funcion de credenciales es imaginaria";
  66. }
  67.  
  68.  
  69. }
  70. }
  71. else
  72. {
  73. # Comprobaciones de sesión o cookies
  74. }
  75.  
  76.  
  77.  
  78. ?>
  79.  
  80. <!DOCTYPE html>
  81. <html>
  82. <head>
  83. </head>
  84. <body>
  85. <form method="POST" action="login.php">
  86. <table>
  87. <tr>
  88. <td>Usuario</td>
  89. <td><input type="text" name="usuario" /></td>
  90. </tr>
  91.  
  92. <tr>
  93. <td>Clave</td>
  94. <td><input type="password" name="clave" /></td>
  95. </tr>
  96. <tr>
  97. <td>Invitado</td>
  98. <td><input type="checkbox" name="invitado" value="inv"/></td>
  99. <tr>
  100. <td>Código</td>
  101. <td><input type="text" name="codigo" /></td>
  102. </tr>
  103. </table>
  104. <button type="submit" name="aceptar">Aceptar</button>
  105. </form>
  106. </body>
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement