3v4l.org

run code in 300+ PHP versions simultaneously
<!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = ""; $name = $email = $gender = $comment = $website = ""; $UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $LOWERCASE = "abcdefghijklmnopqrstuvwxyz"; $NUMBERS = "1234567890"; $SYMBOLS = '`~!@#$%^&*()-_=+[{]}\|;:",<.>/?'; $passwordLength = 0; $availableCharacters = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["passwordLength"])) { $passwordLengthErr = "Length is required"; } else { $passwordLength = test_input($_POST["passwordLength"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $passwordLengthErr = "Only letters and white space allowed"; } } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>PHP Form Validation Example</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Password Length: <input type="text" name="name" value="<?php echo $passwordLength;?>"> <span class="error">* <?php echo $passwordLengthErr;?></span> <br><br> Include Letters: <input type="checkbox" name="vehicle" value="<?php echo $includeLetters;?>" checked> 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> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> </form> <?php echo "<h2>Your Input:</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 = 20, Position 2 = 113
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 75
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 94
Branch analysis from position: 92
1 jumps found. (Code = 42) Position 1 = 101
Branch analysis from position: 101
2 jumps found. (Code = 43) Position 1 = 104, Position 2 = 106
Branch analysis from position: 104
1 jumps found. (Code = 42) Position 1 = 113
Branch analysis from position: 113
2 jumps found. (Code = 46) Position 1 = 139, Position 2 = 141
Branch analysis from position: 139
2 jumps found. (Code = 43) Position 1 = 142, Position 2 = 143
Branch analysis from position: 142
2 jumps found. (Code = 46) Position 1 = 146, Position 2 = 148
Branch analysis from position: 146
2 jumps found. (Code = 43) Position 1 = 149, Position 2 = 150
Branch analysis from position: 149
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 150
Branch analysis from position: 148
Branch analysis from position: 143
Branch analysis from position: 141
Branch analysis from position: 106
2 jumps found. (Code = 46) Position 1 = 139, Position 2 = 141
Branch analysis from position: 139
Branch analysis from position: 141
Branch analysis from position: 94
2 jumps found. (Code = 43) Position 1 = 104, Position 2 = 106
Branch analysis from position: 104
Branch analysis from position: 106
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 89
Branch analysis from position: 88
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 94
Branch analysis from position: 92
Branch analysis from position: 94
Branch analysis from position: 89
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 70
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 75
Branch analysis from position: 73
Branch analysis from position: 75
Branch analysis from position: 70
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
Branch analysis from position: 56
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
Branch analysis from position: 44
Branch analysis from position: 39
Branch analysis from position: 113
filename:       /in/FcqrA
function name:  (null)
number of ops:  165
compiled vars:  !0 = $nameErr, !1 = $emailErr, !2 = $genderErr, !3 = $websiteErr, !4 = $name, !5 = $email, !6 = $gender, !7 = $comment, !8 = $website, !9 = $UPPERCASE, !10 = $LOWERCASE, !11 = $NUMBERS, !12 = $SYMBOLS, !13 = $passwordLength, !14 = $availableCharacters, !15 = $passwordLengthErr, !16 = $includeLetters
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   ECHO                                                     '%3C%21DOCTYPE+HTML%3E+%0A%3Chtml%3E%0A%3Chead%3E%0A%3Cstyle%3E%0A.error+%7Bcolor%3A+%23FF0000%3B%7D%0A%3C%2Fstyle%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E+%0A%0A'
   12     1        ASSIGN                                           ~17     !3, ''
          2        ASSIGN                                           ~18     !2, ~17
          3        ASSIGN                                           ~19     !1, ~18
          4        ASSIGN                                                   !0, ~19
   13     5        ASSIGN                                           ~21     !8, ''
          6        ASSIGN                                           ~22     !7, ~21
          7        ASSIGN                                           ~23     !6, ~22
          8        ASSIGN                                           ~24     !5, ~23
          9        ASSIGN                                                   !4, ~24
   16    10        ASSIGN                                                   !9, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
   17    11        ASSIGN                                                   !10, 'abcdefghijklmnopqrstuvwxyz'
   18    12        ASSIGN                                                   !11, '1234567890'
   19    13        ASSIGN                                                   !12, '%60%7E%21%40%23%24%25%5E%26%2A%28%29-_%3D%2B%5B%7B%5D%7D%5C%7C%3B%3A%22%2C%3C.%3E%2F%3F'
   21    14        ASSIGN                                                   !13, 0
   22    15        ASSIGN                                                   !14, ''
   24    16        FETCH_R                      global              ~32     '_SERVER'
         17        FETCH_DIM_R                                      ~33     ~32, 'REQUEST_METHOD'
         18        IS_EQUAL                                                 ~33, 'POST'
         19      > JMPZ                                                     ~34, ->113
   25    20    >   FETCH_IS                                         ~35     '_POST'
         21        ISSET_ISEMPTY_DIM_OBJ                         1          ~35, 'passwordLength'
         22      > JMPZ                                                     ~36, ->25
   26    23    >   ASSIGN                                                   !15, 'Length+is+required'
         24      > JMP                                                      ->39
   28    25    >   INIT_FCALL_BY_NAME                                       'test_input'
         26        CHECK_FUNC_ARG                                           
         27        FETCH_FUNC_ARG               global              $38     '_POST'
         28        FETCH_DIM_FUNC_ARG                               $39     $38, 'passwordLength'
         29        SEND_FUNC_ARG                                            $39
         30        DO_FCALL                                      0  $40     
         31        ASSIGN                                                   !13, $40
   30    32        INIT_FCALL                                               'preg_match'
         33        SEND_VAL                                                 '%2F%5E%5Ba-zA-Z+%5D%2A%24%2F'
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                         $42     
         36        BOOL_NOT                                         ~43     $42
         37      > JMPZ                                                     ~43, ->39
   31    38    >   ASSIGN                                                   !15, 'Only+letters+and+white+space+allowed'
   35    39    >   FETCH_IS                                         ~45     '_POST'
         40        ISSET_ISEMPTY_DIM_OBJ                         1          ~45, 'gender'
         41      > JMPZ                                                     ~46, ->44
   36    42    >   ASSIGN                                                   !2, 'Gender+is+required'
         43      > JMP                                                      ->51
   38    44    >   INIT_FCALL_BY_NAME                                       'test_input'
         45        CHECK_FUNC_ARG                                           
         46        FETCH_FUNC_ARG               global              $48     '_POST'
         47        FETCH_DIM_FUNC_ARG                               $49     $48, 'gender'
         48        SEND_FUNC_ARG                                            $49
         49        DO_FCALL                                      0  $50     
         50        ASSIGN                                                   !6, $50
   41    51    >   FETCH_IS                                         ~52     '_POST'
         52        ISSET_ISEMPTY_DIM_OBJ                         1          ~52, 'email'
         53      > JMPZ                                                     ~53, ->56
   42    54    >   ASSIGN                                                   !1, 'Email+is+required'
         55      > JMP                                                      ->70
   44    56    >   INIT_FCALL_BY_NAME                                       'test_input'
         57        CHECK_FUNC_ARG                                           
         58        FETCH_FUNC_ARG               global              $55     '_POST'
         59        FETCH_DIM_FUNC_ARG                               $56     $55, 'email'
         60        SEND_FUNC_ARG                                            $56
         61        DO_FCALL                                      0  $57     
         62        ASSIGN                                                   !5, $57
   46    63        INIT_FCALL                                               'filter_var'
         64        SEND_VAR                                                 !5
         65        SEND_VAL                                                 274
         66        DO_ICALL                                         $59     
         67        BOOL_NOT                                         ~60     $59
         68      > JMPZ                                                     ~60, ->70
   47    69    >   ASSIGN                                                   !1, 'Invalid+email+format'
   51    70    >   FETCH_IS                                         ~62     '_POST'
         71        ISSET_ISEMPTY_DIM_OBJ                         1          ~62, 'website'
         72      > JMPZ                                                     ~63, ->75
   52    73    >   ASSIGN                                                   !8, ''
         74      > JMP                                                      ->89
   54    75    >   INIT_FCALL_BY_NAME                                       'test_input'
         76        CHECK_FUNC_ARG                                           
         77        FETCH_FUNC_ARG               global              $65     '_POST'
         78        FETCH_DIM_FUNC_ARG                               $66     $65, 'website'
         79        SEND_FUNC_ARG                                            $66
         80        DO_FCALL                                      0  $67     
         81        ASSIGN                                                   !8, $67
   56    82        INIT_FCALL                                               'preg_match'
         83        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'
         84        SEND_VAR                                                 !8
         85        DO_ICALL                                         $69     
         86        BOOL_NOT                                         ~70     $69
         87      > JMPZ                                                     ~70, ->89
   57    88    >   ASSIGN                                                   !3, 'Invalid+URL'
   61    89    >   FETCH_IS                                         ~72     '_POST'
         90        ISSET_ISEMPTY_DIM_OBJ                         1          ~72, 'comment'
         91      > JMPZ                                                     ~73, ->94
   62    92    >   ASSIGN                                                   !7, ''
         93      > JMP                                                      ->101
   64    94    >   INIT_FCALL_BY_NAME                                       'test_input'
         95        CHECK_FUNC_ARG                                           
         96        FETCH_FUNC_ARG               global              $75     '_POST'
         97        FETCH_DIM_FUNC_ARG                               $76     $75, 'comment'
         98        SEND_FUNC_ARG                                            $76
         99        DO_FCALL                                      0  $77     
        100        ASSIGN                                                   !7, $77
   67   101    >   FETCH_IS                                         ~79     '_POST'
        102        ISSET_ISEMPTY_DIM_OBJ                         1          ~79, 'gender'
        103      > JMPZ                                                     ~80, ->106
   68   104    >   ASSIGN                                                   !2, 'Gender+is+required'
        105      > JMP                                                      ->113
   70   106    >   INIT_FCALL_BY_NAME                                       'test_input'
        107        CHECK_FUNC_ARG                                           
        108        FETCH_FUNC_ARG               global              $82     '_POST'
        109        FETCH_DIM_FUNC_ARG                               $83     $82, 'gender'
        110        SEND_FUNC_ARG                                            $83
        111        DO_FCALL                                      0  $84     
        112        ASSIGN                                                   !6, $84
   81   113    >   ECHO                                                     '%0A%3Ch2%3EPHP+Form+Validation+Example%3C%2Fh2%3E%0A%3Cp%3E%3Cspan+class%3D%22error%22%3E%2A+required+field.%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cform+method%3D%22post%22+action%3D%22'
   84   114        INIT_FCALL                                               'htmlspecialchars'
        115        FETCH_R                      global              ~86     '_SERVER'
        116        FETCH_DIM_R                                      ~87     ~86, 'PHP_SELF'
        117        SEND_VAL                                                 ~87
        118        DO_ICALL                                         $88     
        119        ECHO                                                     $88
        120        ECHO                                                     '%22%3E+%0A+++Password+Length%3A+%3Cinput+type%3D%22text%22+name%3D%22name%22+value%3D%22'
   85   121        ECHO                                                     !13
        122        ECHO                                                     '%22%3E%0A+++%3Cspan+class%3D%22error%22%3E%2A+'
   86   123        ECHO                                                     !15
        124        ECHO                                                     '%3C%2Fspan%3E%0A+++%3Cbr%3E%3Cbr%3E%0A+++Include+Letters%3A++%3Cinput+type%3D%22checkbox%22+name%3D%22vehicle%22+value%3D%22'
   88   125        ECHO                                                     !16
        126        ECHO                                                     '%22+checked%3E%0A+++%0A+++%0A+++E-mail%3A+%3Cinput+type%3D%22text%22+name%3D%22email%22+value%3D%22'
   91   127        ECHO                                                     !5
        128        ECHO                                                     '%22%3E%0A+++%3Cspan+class%3D%22error%22%3E%2A+'
   92   129        ECHO                                                     !1
        130        ECHO                                                     '%3C%2Fspan%3E%0A+++%3Cbr%3E%3Cbr%3E%0A+++Website%3A+%3Cinput+type%3D%22text%22+name%3D%22website%22+value%3D%22'
   94   131        ECHO                                                     !8
        132        ECHO                                                     '%22%3E%0A+++%3Cspan+class%3D%22error%22%3E'
   95   133        ECHO                                                     !3
        134        ECHO                                                     '%3C%2Fspan%3E%0A+++%3Cbr%3E%3Cbr%3E%0A+++Comment%3A+%3Ctextarea+name%3D%22comment%22+rows%3D%225%22+cols%3D%2240%22%3E'
   97   135        ECHO                                                     !7
        136        ECHO                                                     '%3C%2Ftextarea%3E%0A+++%3Cbr%3E%3Cbr%3E%0A+++Gender%3A%0A+++%3Cinput+type%3D%22radio%22+name%3D%22gender%22+'
  100   137        ISSET_ISEMPTY_CV                                 ~89     !6
        138      > JMPZ_EX                                          ~89     ~89, ->141
        139    >   IS_EQUAL                                         ~90     !6, 'female'
        140        BOOL                                             ~89     ~90
        141    > > JMPZ                                                     ~89, ->143
        142    >   ECHO                                                     'checked'
        143    >   ECHO                                                     '++value%3D%22female%22%3EFemale%0A+++%3Cinput+type%3D%22radio%22+name%3D%22gender%22+'
  101   144        ISSET_ISEMPTY_CV                                 ~91     !6
        145      > JMPZ_EX                                          ~91     ~91, ->148
        146    >   IS_EQUAL                                         ~92     !6, 'male'
        147        BOOL                                             ~91     ~92
        148    > > JMPZ                                                     ~91, ->150
        149    >   ECHO                                                     'checked'
        150    >   ECHO                                                     '++value%3D%22male%22%3EMale%0A+++%3Cspan+class%3D%22error%22%3E%2A+'
  102   151        ECHO                                                     !2
        152        ECHO                                                     '%3C%2Fspan%3E%0A+++%3Cbr%3E%3Cbr%3E%0A+++%3Cinput+type%3D%22submit%22+name%3D%22submit%22+value%3D%22Submit%22%3E+%0A%3C%2Fform%3E%0A%0A'
  108   153        ECHO                                                     '%3Ch2%3EYour+Input%3A%3C%2Fh2%3E'
  109   154        ECHO                                                     !4
  110   155        ECHO                                                     '%3Cbr%3E'
  111   156        ECHO                                                     !5
  112   157        ECHO                                                     '%3Cbr%3E'
  113   158        ECHO                                                     !8
  114   159        ECHO                                                     '%3Cbr%3E'
  115   160        ECHO                                                     !7
  116   161        ECHO                                                     '%3Cbr%3E'
  117   162        ECHO                                                     !6
  119   163        ECHO                                                     '%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
  121   164      > RETURN                                                   1

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

End of function test_input

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.09 ms | 1416 KiB | 23 Q