Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="es">
  3. <head>
  4. <meta charset="utf-8"> <title>santiago</title>
  5. </head>
  6. <body>
  7. <form method="POST">
  8. <input type="text" name="user" placeholder="input user"/>
  9. <input type="text" name="pass" placeholder="input pass"/>
  10. <input type="submit" name="send" value="Log In"/>
  11. </form>
  12. </body>
  13.  
  14. <?php
  15. final class Validate
  16. {
  17.  
  18. public function type_data($data, $type) {
  19. #integer, double, NULL, object, string
  20. if(gettype($data) == $type)
  21. echo "correcto";
  22. else{
  23. try {
  24. settype($data, $type); // se intenta convertir en tipo de dato especificado
  25. echo gettype($data);
  26. return $data;
  27. } catch (Exception $e) {
  28. echo "no se ha podido convertir";
  29. //echo 'Excepción capturada: ', $e->getMessage(), "\n";
  30. }
  31. }
  32. }
  33.  
  34. public function extencion($data, $length){
  35. if(strlen($data) > $length)
  36. $data = substr($data, 0, $length); // recortara la cadena
  37. return $data;
  38. }
  39. public function entidades_html($data) {
  40. // convertimos en entidades html los caracteres < >
  41. $data = str_replace("<", "&#60", $data);
  42. $data = str_replace(">", "&#62", $data);
  43. return $data;
  44. }
  45. public function only_num_letter($data){
  46. // eliminamos lo que no es un numero o letra
  47. $data = ereg_replace("[^A-Za-z0-9]", "", $data);
  48. return $data;
  49. }
  50. }
  51.  
  52. if(isset($_POST["send"]))
  53. {
  54. $user = $_POST["user"];
  55. $pass = $_POST["pass"];
  56.  
  57. if(!empty($user) and !empty($pass)){
  58. // validando campos
  59. $o_validar = new Validate();
  60. //echo $user = $o_validar->extencion($user, 5);
  61. echo $pass = $o_validar->type_data($pass ,"integer");
  62. //$user = $o_validar->only_num_letter($user);
  63. //$pass = $o_validar->only_num_letter($pass);
  64. //echo $pass;
  65.  
  66. }
  67. else{ die("campos vacios, VETE"); }
  68. }
  69. else{
  70. //echo "&#62";
  71. }
  72.  
  73. ?>
  74.  
  75. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement