3v4l.org

run code in 300+ PHP versions simultaneously
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Validación en PHP</title> <style> .error {color: #FF0000;} </style> </head> <body> <?php // Variables que contendrán un posible mensaje de error $nameErr = $emailErr = $genderErr = $websiteErr = ""; // Variables que guardan el contenido de los campos del formulario $name = $email = $gender = $comment = $website = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Nombre necesario"; } else { $name = test_input($_POST["name"]); // verificar si el nombre contiene solo letras y espacios en blanco if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Solo se permiten letras y espacios en blanco"; } } if (empty($_POST["email"])) { $emailErr = "Email necesario"; } else { $email = test_input($_POST["email"]); // verificar si la direccion de correo es valida if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $emailErr = "Formato de dirección inválido"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // verifica si la URL es válida (la expresion regular también permite guiones en la URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "URL con capacidades diferentes"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])) { $genderErr = "Genero necesario"; } else { $gender = test_input($_POST["gender"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>Ejemplo de Validación de Formularios con PHP</h2> <p><span class="error">* campo requerido.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Nombre: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Comentario: <textarea name="comment" rows="5" cols="40"></textarea> <br><br> Genero: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="femenino") echo "checked";?> value="femenino">Femenino <input type="radio" name="gender" <?php if (isset($gender) && $gender=="masculino") echo "checked";?> value="masculino">Masculino <span class="error">* <?php echo $genderErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> </form> <?php echo "<h2>Usted Ingresó:</h2>"; echo $name; echo "<br>"; echo $email; echo "<br>"; echo $website; echo "<br>"; echo $comment; echo "<br>"; echo $gender; ?> </body> </html>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 95
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 88
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 95
Branch analysis from position: 95
2 jumps found. (Code = 46) Position 1 = 117, Position 2 = 119
Branch analysis from position: 117
2 jumps found. (Code = 43) Position 1 = 120, Position 2 = 121
Branch analysis from position: 120
2 jumps found. (Code = 46) Position 1 = 124, Position 2 = 126
Branch analysis from position: 124
2 jumps found. (Code = 43) Position 1 = 127, Position 2 = 128
Branch analysis from position: 127
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 128
Branch analysis from position: 126
Branch analysis from position: 121
Branch analysis from position: 119
Branch analysis from position: 88
2 jumps found. (Code = 46) Position 1 = 117, Position 2 = 119
Branch analysis from position: 117
Branch analysis from position: 119
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 88
Branch analysis from position: 86
Branch analysis from position: 88
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 71
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
Branch analysis from position: 76
Branch analysis from position: 71
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 52
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
Branch analysis from position: 57
Branch analysis from position: 52
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
Branch analysis from position: 38
Branch analysis from position: 33
Branch analysis from position: 95
filename:       /in/VsFH1
function name:  (null)
number of ops:  143
compiled vars:  !0 = $nameErr, !1 = $emailErr, !2 = $genderErr, !3 = $websiteErr, !4 = $name, !5 = $email, !6 = $gender, !7 = $comment, !8 = $website
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   ECHO                                                     '%3C%21DOCTYPE+HTML%3E%0A%0A%3Chtml%3E%0A%0A%3Chead%3E%0A%0A++%3Cmeta+charset%3D%22utf-8%22%3E%0A%0A++%3Ctitle%3EValidaci%C3%B3n+en+PHP%3C%2Ftitle%3E%0A%0A++%3Cstyle%3E%0A%0A++++.error+%7Bcolor%3A+%23FF0000%3B%7D%0A%0A++%3C%2Fstyle%3E%0A%0A%3C%2Fhead%3E%0A%0A%3Cbody%3E%0A%0A++'
   25     1        ASSIGN                                           ~9      !3, ''
          2        ASSIGN                                           ~10     !2, ~9
          3        ASSIGN                                           ~11     !1, ~10
          4        ASSIGN                                                   !0, ~11
   29     5        ASSIGN                                           ~13     !8, ''
          6        ASSIGN                                           ~14     !7, ~13
          7        ASSIGN                                           ~15     !6, ~14
          8        ASSIGN                                           ~16     !5, ~15
          9        ASSIGN                                                   !4, ~16
   31    10        FETCH_R                      global              ~18     '_SERVER'
         11        FETCH_DIM_R                                      ~19     ~18, 'REQUEST_METHOD'
         12        IS_EQUAL                                                 ~19, 'POST'
         13      > JMPZ                                                     ~20, ->95
   33    14    >   FETCH_IS                                         ~21     '_POST'
         15        ISSET_ISEMPTY_DIM_OBJ                         1          ~21, 'name'
         16      > JMPZ                                                     ~22, ->19
   35    17    >   ASSIGN                                                   !0, 'Nombre+necesario'
         18      > JMP                                                      ->33
   39    19    >   INIT_FCALL_BY_NAME                                       'test_input'
         20        CHECK_FUNC_ARG                                           
         21        FETCH_FUNC_ARG               global              $24     '_POST'
         22        FETCH_DIM_FUNC_ARG                               $25     $24, 'name'
         23        SEND_FUNC_ARG                                            $25
         24        DO_FCALL                                      0  $26     
         25        ASSIGN                                                   !4, $26
   43    26        INIT_FCALL                                               'preg_match'
         27        SEND_VAL                                                 '%2F%5E%5Ba-zA-Z+%5D%2A%24%2F'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $28     
         30        BOOL_NOT                                         ~29     $28
         31      > JMPZ                                                     ~29, ->33
   45    32    >   ASSIGN                                                   !0, 'Solo+se+permiten+letras+y+espacios+en+blanco'
   53    33    >   FETCH_IS                                         ~31     '_POST'
         34        ISSET_ISEMPTY_DIM_OBJ                         1          ~31, 'email'
         35      > JMPZ                                                     ~32, ->38
   55    36    >   ASSIGN                                                   !1, 'Email+necesario'
         37      > JMP                                                      ->52
   59    38    >   INIT_FCALL_BY_NAME                                       'test_input'
         39        CHECK_FUNC_ARG                                           
         40        FETCH_FUNC_ARG               global              $34     '_POST'
         41        FETCH_DIM_FUNC_ARG                               $35     $34, 'email'
         42        SEND_FUNC_ARG                                            $35
         43        DO_FCALL                                      0  $36     
         44        ASSIGN                                                   !5, $36
   63    45        INIT_FCALL                                               'preg_match'
         46        SEND_VAL                                                 '%2F%28%5B%5Cw%5C-%5D%2B%5C%40%5B%5Cw%5C-%5D%2B%5C.%5B%5Cw%5C-%5D%2B%29%2F'
         47        SEND_VAR                                                 !5
         48        DO_ICALL                                         $38     
         49        BOOL_NOT                                         ~39     $38
         50      > JMPZ                                                     ~39, ->52
   65    51    >   ASSIGN                                                   !1, 'Formato+de+direcci%C3%B3n+inv%C3%A1lido'
   73    52    >   FETCH_IS                                         ~41     '_POST'
         53        ISSET_ISEMPTY_DIM_OBJ                         1          ~41, 'website'
         54      > JMPZ                                                     ~42, ->57
   75    55    >   ASSIGN                                                   !8, ''
         56      > JMP                                                      ->71
   79    57    >   INIT_FCALL_BY_NAME                                       'test_input'
         58        CHECK_FUNC_ARG                                           
         59        FETCH_FUNC_ARG               global              $44     '_POST'
         60        FETCH_DIM_FUNC_ARG                               $45     $44, 'website'
         61        SEND_FUNC_ARG                                            $45
         62        DO_FCALL                                      0  $46     
         63        ASSIGN                                                   !8, $46
   83    64        INIT_FCALL                                               'preg_match'
         65        SEND_VAL                                                 '%2F%5Cb%28%3F%3A%28%3F%3Ahttps%3F%7Cftp%29%3A%5C%2F%5C%2F%7Cwww%5C.%29%5B-a-z0-9%2B%26%40%23%5C%2F%25%3F%3D%7E_%7C%21%3A%2C.%3B%5D%2A%5B-a-z0-9%2B%26%40%23%5C%2F%25%3D%7E_%7C%5D%2Fi'
         66        SEND_VAR                                                 !8
         67        DO_ICALL                                         $48     
         68        BOOL_NOT                                         ~49     $48
         69      > JMPZ                                                     ~49, ->71
   85    70    >   ASSIGN                                                   !3, 'URL+con+capacidades+diferentes'
   91    71    >   FETCH_IS                                         ~51     '_POST'
         72        ISSET_ISEMPTY_DIM_OBJ                         1          ~51, 'comment'
         73      > JMPZ                                                     ~52, ->76
   93    74    >   ASSIGN                                                   !7, ''
         75      > JMP                                                      ->83
   97    76    >   INIT_FCALL_BY_NAME                                       'test_input'
         77        CHECK_FUNC_ARG                                           
         78        FETCH_FUNC_ARG               global              $54     '_POST'
         79        FETCH_DIM_FUNC_ARG                               $55     $54, 'comment'
         80        SEND_FUNC_ARG                                            $55
         81        DO_FCALL                                      0  $56     
         82        ASSIGN                                                   !7, $56
  101    83    >   FETCH_IS                                         ~58     '_POST'
         84        ISSET_ISEMPTY_DIM_OBJ                         1          ~58, 'gender'
         85      > JMPZ                                                     ~59, ->88
  103    86    >   ASSIGN                                                   !2, 'Genero+necesario'
         87      > JMP                                                      ->95
  107    88    >   INIT_FCALL_BY_NAME                                       'test_input'
         89        CHECK_FUNC_ARG                                           
         90        FETCH_FUNC_ARG               global              $61     '_POST'
         91        FETCH_DIM_FUNC_ARG                               $62     $61, 'gender'
         92        SEND_FUNC_ARG                                            $62
         93        DO_FCALL                                      0  $63     
         94        ASSIGN                                                   !6, $63
  126    95    >   ECHO                                                     '%0A++%3Ch2%3EEjemplo+de+Validaci%C3%B3n+de+Formularios+con+PHP%3C%2Fh2%3E%0A%0A++%3Cp%3E%3Cspan+class%3D%22error%22%3E%2A+campo+requerido.%3C%2Fspan%3E%3C%2Fp%3E%0A%0A++%3Cform+method%3D%22post%22+action%3D%22'
  131    96        INIT_FCALL                                               'htmlspecialchars'
         97        FETCH_R                      global              ~65     '_SERVER'
         98        FETCH_DIM_R                                      ~66     ~65, 'PHP_SELF'
         99        SEND_VAL                                                 ~66
        100        DO_ICALL                                         $67     
        101        ECHO                                                     $67
        102        ECHO                                                     '%22%3E%0A%0A+++++Nombre%3A+%3Cinput+type%3D%22text%22+name%3D%22name%22+value%3D%22'
  133   103        ECHO                                                     !4
        104        ECHO                                                     '%22%3E%0A%0A+++++%3Cspan+class%3D%22error%22%3E%2A+'
  135   105        ECHO                                                     !0
        106        ECHO                                                     '%3C%2Fspan%3E%0A%0A+++++%3Cbr%3E%3Cbr%3E%0A%0A+++++E-mail%3A+%3Cinput+type%3D%22text%22+name%3D%22email%22+value%3D%22'
  139   107        ECHO                                                     !5
        108        ECHO                                                     '%22%3E%0A%0A+++++%3Cspan+class%3D%22error%22%3E%2A+'
  141   109        ECHO                                                     !1
        110        ECHO                                                     '%3C%2Fspan%3E%0A%0A+++++%3Cbr%3E%3Cbr%3E%0A%0A+++++Website%3A+%3Cinput+type%3D%22text%22+name%3D%22website%22+value%3D%22'
  145   111        ECHO                                                     !8
        112        ECHO                                                     '%22%3E%0A%0A+++++%3Cspan+class%3D%22error%22%3E'
  147   113        ECHO                                                     !3
        114        ECHO                                                     '%3C%2Fspan%3E%0A%0A+++++%3Cbr%3E%3Cbr%3E%0A%0A+++++Comentario%3A+%3Ctextarea+name%3D%22comment%22+rows%3D%225%22+cols%3D%2240%22%3E%3C%2Ftextarea%3E%0A%0A+++++%3Cbr%3E%3Cbr%3E%0A%0A+++++Genero%3A%0A%0A+++++%3Cinput+type%3D%22radio%22+name%3D%22gender%22%0A%0A++++++++'
  159   115        ISSET_ISEMPTY_CV                                 ~68     !6
        116      > JMPZ_EX                                          ~68     ~68, ->119
        117    >   IS_EQUAL                                         ~69     !6, 'femenino'
        118        BOOL                                             ~68     ~69
        119    > > JMPZ                                                     ~68, ->121
        120    >   ECHO                                                     'checked'
        121    >   ECHO                                                     '++%0A%0A++++++++value%3D%22femenino%22%3EFemenino%0A%0A+++++%3Cinput+type%3D%22radio%22+name%3D%22gender%22%0A%0A++++++++'
  165   122        ISSET_ISEMPTY_CV                                 ~70     !6
        123      > JMPZ_EX                                          ~70     ~70, ->126
        124    >   IS_EQUAL                                         ~71     !6, 'masculino'
        125        BOOL                                             ~70     ~71
        126    > > JMPZ                                                     ~70, ->128
        127    >   ECHO                                                     'checked'
  166   128    >   ECHO                                                     '%0A+++++value%3D%22masculino%22%3EMasculino%0A%0A+++++%3Cspan+class%3D%22error%22%3E%2A+'
  169   129        ECHO                                                     !2
        130        ECHO                                                     '%3C%2Fspan%3E%0A%0A+++++%3Cbr%3E%3Cbr%3E%0A%0A+++++%3Cinput+type%3D%22submit%22+name%3D%22submit%22+value%3D%22Submit%22%3E%0A%0A++%3C%2Fform%3E%0A%0A++'
  179   131        ECHO                                                     '%3Ch2%3EUsted+Ingres%C3%B3%3A%3C%2Fh2%3E'
  181   132        ECHO                                                     !4
  183   133        ECHO                                                     '%3Cbr%3E'
  185   134        ECHO                                                     !5
  187   135        ECHO                                                     '%3Cbr%3E'
  189   136        ECHO                                                     !8
  191   137        ECHO                                                     '%3Cbr%3E'
  193   138        ECHO                                                     !7
  195   139        ECHO                                                     '%3Cbr%3E'
  197   140        ECHO                                                     !6
  200   141        ECHO                                                     '%0A%3C%2Fbody%3E%0A%0A%3C%2Fhtml%3E'
  203   142      > RETURN                                                   1

Function test_input:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VsFH1
function name:  test_input
number of ops:  15
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     0  E >   RECV                                             !0      
  115     1        INIT_FCALL                                               'trim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
  117     5        INIT_FCALL                                               'stripslashes'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !0, $3
  119     9        INIT_FCALL                                               'htmlspecialchars'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $5      
         12        ASSIGN                                                   !0, $5
  121    13      > RETURN                                                   !0
  123    14*     > RETURN                                                   null

End of function test_input

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.69 ms | 1412 KiB | 21 Q