Results 1 to 2 of 2

Thread: Login Feature (To see pages)

  1. #1
    Join Date
    Oct 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Login Feature (To see pages)

    Hey guys, I was wondering is there a DynamicDrive code to login to see a page or pages?

    Pretty sure this is a PHP coding question, but it may be ASP, so sorry if I posted in wrong area.

    Just in case you need my site, here it is. Website

    Thanks a lot guys.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can do it in either language. I don't know ASP, so in PHP:
    PHP Code:
    <?php
    $password 
    "put your password here";

    $login_form = <<<END
    <!-- Put your login form here, in plain HTML. -->
    <html>
      <head>
        <title>Authorization Required</title>
      </head>
      <body>
        <p>
          This page is for members only.  If you are a member, please enter your password below.  If not, please leave this page.
        </p>
        <fieldset>
          <form action="
    $PHP_SELF" method="post">
            <legend>Password</legend>
            <input type="password" name="password"/>
            <input type="submit" value="OK"/>
          </form>
        </fieldset>
      </body>
    </html>

    END;
    $login_failed = <<<END
    <!-- Put your "authorization failed" page here, in plain HTML. -->
    <html>
      <head>
        <title>Authorization Failed</title>
      </head>
      <body>
        <p>
          Your login failed!  Please try again by entering your password in the field below.
        </p>
        <fieldset>
          <form action="
    $PHP_SELF" method="post">
            <legend>Password</legend>
            <input type="password" name="password"/>
            <input type="submit" value="OK"/>
          </form>
        </fieldset>
      </body>
    </html>

    END;
    session_start();
    if(!isset(
    $_SESSION['logged_in']) && !isset($_POST['password']))
      die(
    $login_form);
    if(isset(
    $_POST['password']))
      if(
    $_POST['password'] == $password)
        
    $_SESSION['logged_in'] = 1;
      else die(
    $login_failed);
    ?>
    Save this to a seperate file (such as security.php), then, at the top of your file(s) (before anything else), put:
    Code:
    include("security.php");
    Untested.
    Last edited by Twey; 12-08-2005 at 05:45 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •