Jump to content
mastermicio

myphplogingang

Recommended Posts

<!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>

Share this post


Link to post
Share on other sites

Hi there, 

Welcome to the forums, please include your code in a code block, and include the question in your post.

Thanks.

XcQfW3F.png

Share this post


Link to post
Share on other sites

What's your question?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...