Jump to content

mastermicio

Members
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About mastermicio

  • Rank
    Newbie
  1. mastermicio

    myphplogingang

    <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php // define variables and set to empty values $nameErr = $passwordErr = ""; $name = $password = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); } if (empty($_POST["password"])) { $passwordErr = "password is required"; } else { $password = test_input($_POST["password"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <form method="post" action="index.php"> Name: <input type="text" name="name"> <span class="error">* <?php echo $nameErr; ?></span> <br><br> password: <input type="text" name="password"> <span class="error">* <?php echo $passwordErr; ?></span> <br><br> <br><br> <input type="submit" name="submit" value="Submit"> </form> <?php if (!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{6,8}$/', $password)) { ?> <span class="error">* <?php echo 'la password deve essere tra i 6 e gli 8 caratteri, contenere un numero e una lettera maiuscola'; ?></span> <?php } else { $myfile = fopen("login.txt", "a+") or die("Unable to open file!"); fwrite($myfile, $name . ", " . $password . "\r\n"); fclose($myfile); } ?> <?php $nameErr = $passwordErr = ""; $name = $password = ""; ?> <br><br><br><br> Login:<br> Name: <input type="text" name="name"> <span class="error">* <?php echo $nameErr; ?></span> <br><br> password: <input type="text" name="password"> <span class="error">* <?php echo $passwordErr; ?></span> <br><br> <br><br> <input type="submit" name="submit" value="Submit"> </form> <?php $myfile = fopen("login.txt", "r"); while(!feof($myfile)){ $riga = fgets($myfile); $array = explode(",",$riga); if ($riga[0]==$name && $riga[1]==$password){ echo "benevenuto"; } echo $riga."<br>"; } fclose($myfile); ?> </body> </html>
×
×
  • Create New...