mastermicio Posted January 30, 2020 Share Posted January 30, 2020 <!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> Link to comment Share on other sites More sharing options...
Funce Posted February 4, 2020 Share Posted February 4, 2020 Hi there, Welcome to the forums, please include your code in a code block, and include the question in your post. Thanks. Link to comment Share on other sites More sharing options...
niche Posted February 5, 2020 Share Posted February 5, 2020 What's your question? Link to comment Share on other sites More sharing options...
dsonesuk Posted February 5, 2020 Share Posted February 5, 2020 No opening form element for login form perhaps. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now