• home
  • forum
  • my
  • kt
  • download
  • Advanced Password Protect a Webpage

    Author: 2008-08-16 11:04:49 From:

    You can find a demo of the script here.

    Okay, bring up notepad or whatever text editor you use and paste this code into it:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <?php

    //EDITABLE -->
    $title[0] = "Please Log In.";
    $title[1] = "Access Restrictions.";
    $title[2] = "Your moma bakes gravy for lepars.";
    $title[3] = "OMFG IM PASSWORDED SINCE WHEN?!";
    $username = "username";
    $password = "password";

    //NO MORE -->
    if(isset($_POST['tuser']) && isset($_POST['tpass'])){
    $user = $_POST['tuser']; $pass = $_POST['tpass'];
    if($user=="" || $pass==""){
    $error = $error."You left a field or fields blank.<br/>";
    } else {
    if($user=="" && $pass==""){
    $error = $error."You left both fields blank.";
    }
    }
    $user = md5($user); $pass = md5($pass);
    //if both user and pass exist, log in!
    if($user !=="" && $pass!==""){
    if($user == md5($username) && $pass == md5($password)){
    $loggedin = true;
    } else {
    $error = $error."Invalid username or password.";
    }
    }
    }
    $maxarray = count($title)-1;
    $choice = rand(0,$maxarray);
    echo "<title>".$title[$choice]."</title>";
    if(!$loggedin){?>
    <style type='text/css'>
    body {
    background: #a0a0a0;
    font-family: verdana;
    }
    <? } ?>

    <?// IF YOU WANT MORE CSS PUT IT HERE YOU FAGGOT ?>

    </style>
    </head>
    <body>
    <?php
    if(!$loggedin){
    echo "
    <table><tr><td align='center'>
    <table width='320px' height='128px' align='center' style='border: #000 3px double; background: #f0f0f0;'><tr><td>
    <form method='post' action='".basename($_SERVER['PHP_SELF'])."' name='login'><table><tr>
    <td width='128px'><label for='tuser'>Username: </label></td><td width='256px'><input type='text' name='tuser' value='' size='20'></td></tr><td width='128px'><label for='tpass'>Password: </label></td><td width='256px'><input type='password' name='tpass' value='' size='20' onClick=\"value=''\"></td></tr></table>
    <table><tr><td width='180px'><font color='#ff0033' style='font-size:9px;'><b>$error</b></font></td><td width='64px'><input type='submit' name='submit' value='Login'></td></tr></table></form></td></tr>
    </table>
    ";
    } else {
    ?>



    All HTML and other stuff goes hereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee



    <?
    }
    ?>
    </body></html>




    I placed all the editable details in blue font and all uneditable in red. Save your code once you've edited the values of the variables - you should have this if you don't want the variable to be used:
    $var = "";

    Add as many arrays as you want for the random title thing.. that was just a joke anyway..


    Save the file as index.php and upload it to your webspace. (yes, funnily enough you need webspace)

    Now follow the URL to your index.php and you should see a login screen. Just enter the username and password you defined. You're good to go!

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (9)
      Link Indexing (6)
      Mailing List Management (8)
      Miscellaneous (10)
      Networking (6)
      News Publishing (6)
      OOP (8)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (5)
      Postcards (0)
      Randomizing (8)
      Redirection (8)
      Searching (6)
      Security (14)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot