Skip to main content
Participant
July 14, 2020
Question

create login/password for a specific page

  • July 14, 2020
  • 2 replies
  • 238 views

I'm creating a customer page that will require a user/password in order to access. Is there a simple method?

Thanks.

    This topic has been closed for replies.

    2 replies

    Nancy OShea
    Community Expert
    Community Expert
    July 14, 2020

    Alternatively, you could use your hosting plan's Plesk or c-Panel to create a password protected folder on your server.  Ask your hosting provider for details.

     

    Nancy O'Shea— Product User & Community Expert
    Nancy OShea
    Community Expert
    Community Expert
    July 14, 2020

    This is a very simple one page app with PHP script to hide content until the user enters a correct ID & password.  Save as protect.php and upload to a server that supports PHP code.

     

     

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Password Protected Content</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    
    <!--minimal demo styles-->
    <style>
    html {font-size:16px}
    
    body {font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, "sans-serif";
    font-size: 1.5rem;
    width:80%;
    margin:0 auto;
    }
    </style>
    </head>
    <body>
    
    <?php
    // Define your username and password here
    $username = "admin";
    $password = "pass123";
    
    if (isset($_POST['txtUsername']) != $username || $_POST['txtPassword'] != $password) {
    ?>
    <!--LOG-IN FORM-->
    <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
    <legend>Log-In</legend>
    
    <p><label for="txtUsername">Username:</label>
    <br>
    <input type="text" title="Enter your Username" name="txtUsername" id="txtUsername" required placeholder="5 characters"></p>
    
    <p><label for="txtPassword">Password:</label>
    <br>
    <input type="password" title="Enter your password" name="txtPassword" id="txtPassword" required placeholder="7 characters"></p>
    
    <button type="submit" class="btn btn-lg btn-primary">Submit</button>
    </fieldset>
    </form>
    
    <?php
    }
    else {
    ?>
    
    <!--PROTECTED CONTENT-->
    <h2>Log-In Success!</h2>
    <p>You have reached a password protected area of this page. What would you like to do next?</p>
    
    <!--Links to other pages-->
    <ul>
    <li> <a href="#">Download Files</a></li>
    <li><a href="#">Upload Files</a></li>
    <li><a href="#">Watch Videos</a></li>
    <li><a href="#">Play a Game</a></li>
    </ul>
    <?php
    }
    ?> 
    <!--END PROTECTED CONTENT-->
    
    </body>
    </html>

     

     

    Nancy O'Shea— Product User & Community Expert