SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist rhysboy84's Avatar
    Join Date
    May 2007
    Location
    Colwyn Bay, North Wales, UK
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie: Looking for some help building a login form

    Hi everybody!

    I'm playing around with PHP & MySQL at the moment, and am trying to learn various ways to do things and hopefully - in time - build up an application.

    What I'm trying to do (more because a mate wanted one, and I want to see how they work), is creating a login form. The form will check a database for values for username and password, and if they match the result from the login form, they'd allow you into the directory (say "admin").

    Now I can create said login form to check for the variables if there is a admin/login.php form. However, any other file in the admin/ directory is visible anyway, login form or not.

    Any help on how to create it (tutorials mainly) would be greatfully appreciated!

    Thanks
    I'm Rhys Wynne & I blog at Winwar Media
    WP Email Capture: Free Email/Ebook Marketing Wordpress Plugin
    UK Based SEO? Tweet Your Location to #ukseohere!
    | My Brand New Brand | Twitter |

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The basic idea is to put a snippet at the top of each page you want to protect like this:

    PHP Code:
    <?php
    session_start
    ();
    if (!isset(
    $_SESSION['logged_in'])) {
      
    header("Location: login.php");
      exit;
    }
    ?>
    Your login script sets that session variable. Then any request to any protected page will redirect to the login form if the user is not logged in.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •