Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="es">
- <head>
- <meta charset="utf-8"> <title>santiago</title>
- </head>
- <body>
- <form method="POST">
- <input type="text" name="user" placeholder="input user"/>
- <input type="text" name="pass" placeholder="input pass"/>
- <input type="submit" name="send" value="Log In"/>
- </form>
- </body>
- <?php
- final class Validate
- {
- public function type_data($data, $type) {
- #integer, double, NULL, object, string
- if(gettype($data) == $type)
- echo "correcto";
- else{
- try {
- settype($data, $type); // se intenta convertir en tipo de dato especificado
- echo gettype($data);
- return $data;
- } catch (Exception $e) {
- echo "no se ha podido convertir";
- //echo 'Excepción capturada: ', $e->getMessage(), "\n";
- }
- }
- }
- public function extencion($data, $length){
- if(strlen($data) > $length)
- $data = substr($data, 0, $length); // recortara la cadena
- return $data;
- }
- public function entidades_html($data) {
- // convertimos en entidades html los caracteres < >
- $data = str_replace("<", "<", $data);
- $data = str_replace(">", ">", $data);
- return $data;
- }
- public function only_num_letter($data){
- // eliminamos lo que no es un numero o letra
- $data = ereg_replace("[^A-Za-z0-9]", "", $data);
- return $data;
- }
- }
- if(isset($_POST["send"]))
- {
- $user = $_POST["user"];
- $pass = $_POST["pass"];
- if(!empty($user) and !empty($pass)){
- // validando campos
- $o_validar = new Validate();
- //echo $user = $o_validar->extencion($user, 5);
- echo $pass = $o_validar->type_data($pass ,"integer");
- //$user = $o_validar->only_num_letter($user);
- //$pass = $o_validar->only_num_letter($pass);
- //echo $pass;
- }
- else{ die("campos vacios, VETE"); }
- }
- else{
- //echo ">";
- }
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement