How to Add a Register Login to a Website

How to Add a Register Login to a Website thumbnail
Happy users are users who can access their content.

Login pages are an essential component of most user-driven web pages. They are critical for allowing users to view their content separate from the content other users want to view. A part of creating successful login pages is having good registration pages, which allow users to easily register for your website. While this presents some design problems and will require some forethought, the code to do this is actually relatively easy.

Things You'll Need

  • Web server running PHP and MySQL
Show More

Instructions

    • 1

      Open a blank document in a text editor. As long as it supports saving to arbitrary file formats, any text editor will do.

    • 2

      Add the following code to your file:

      <?php if ($_SERVER['REQUEST_METHOD'] == 'GET') { ?>

      <form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="post">

      Username:<input type="text" name="username" />

      Password:<input type="password" name="password" />

      <input type="submit" value="Log me in!" />

      </form>

      <?php } else {

      $username = $_POST['username'];

      $password = $_POST['password'];

      $query=mysql_query("Select * from users where username=$username and password=$password");

      if(!isset($query)) {

      header('registration.php');

      }

      else {

      header('index.html');

      }

      }

      ?>

      Save this file as "login.php." If the page you're adding the login to is not named "index.html," then replace "index.html" with whatever the URL is of the page to which you want to add a login.

    • 3

      Create a form for your users' registration. It should look something like this:

      <form action="registrationscript.php" method="post">

      Name:<input type="text" name="name" />

      Desired Password: <input type="text" name="name" />

      </form>

      You'll need to add more or fewer fields depending on your requirements. Save this as "registration.php."

    • 4

      Upload these pages to your server. Usually this can be done through your hosting company's web interface.

Related Searches:

References

  • Photo Credit login button image by timur1970 from Fotolia.com

Comments

You May Also Like

Related Ads

Featured