How to Make a Login and Logout on a Website

How to Make a Login and Logout on a Website thumbnail
Code a great log-in page.

Log-in pages are a critical component of many dynamic web applications. They provide an air of authority and security to websites that use them. Additionally, users have come to expect a log-n page on most legitimate websites. Learning to create log-in pages is useful, both for personal projects and for enterprise purposes. Also, log-in pages are relatively easy to code. While web development is an exciting and challenging field, learning the basics is very straightforward.

Things You'll Need

  • Knowledge of PHP (Personal HomePage HyperText Processor)
Show More

Instructions

    • 1

      Write the log-in page. This will be done using XHTML or eXtensible HyperText Markup Language. The code will look something like this:

      "

      <form>

      <input type="text" name="uname" />

      <input type="text" name="pwd" />

      </form>

      "

      You will need to make changes based on your application.

    • 2

      Create a PHP script that checks the input of this form against a text file or database, depending on how you've decided to store your password data. There are thousands of ways to do this. Choose the one that is best suited to your needs.

    • 3

      Set a cookie and use it to keep track of logged-in users. The code to do that will look something like

      "

      <?php

      $_COOKIE['name']="value";

      ?>

      "

      Again, you'll need to modify this to suit your needs.

    • 4

      To log out users, you'll need to change the value of the cookie or destroy it. Possible code will look like this:

      "

      <?php

      $_COOKIE['name']="";

      ?>

      "

      Here we've set the cookie to an empty string. You also have the option to destroy it:

      <?php

      setcookie ("TestCookie", "", time() - 2400);

      ?>

      We've set the cookie's expiration to be in the past here. This ensures the cookie is destroyed immediately.

Related Searches:

References

  • Photo Credit login image by Edvin selimovic from Fotolia.com

Comments

You May Also Like

Related Ads

Featured