Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2008
    Posts
    940
    Tokens
    75

    Default [PHP] Password Protection

    Alright so last night I was up all night just trying to figure this out, and its not even a good one so I need help. Basically I read a ton of Tutorials and I didn't read any good ones. So basically I need a password protected page.

    When logged in with the password its redirected to another page, anyways heres what I have

    PHP Code:
    <?php
    // If password is valid let the user get access
    if (isset($_POST["password"]) && ($_POST["password"]=="$password")) {
    ?>
      <p align="center"><br><br><br>
      <b>Congratulations</b><br>you have gained access to the Protected and Secret Area!</p>

    <?php 
    }
    else
    {
    // Wrong password or no password entered display this message
    if (isset($_POST['password']) || $password == "") {
      print 
    "<p align=\"center\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>";}
      print 
    "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>";
      print 
    "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>";
    }

    + Rep to all who help


  2. #2
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    index.php
    PHP Code:
    <?php
    session_start
    ();

    $password "test";

    if(
    $_SESSION["logged_password"] == $password) {
            
    header('Location: page.php');
    }
    if(isset(
    $_POST["password"])) {

        if(
    $_POST["password"] == "") {
            echo(
    "<p align=\"center\"><font color=\"red\"><b>You didn't enter a password!</b><br>Please enter the correct password</font></p>");
        } elseif(
    $_POST["password"] != $password) {
            echo(
    "<p align=\"center\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>");
        } else {
            
    $_SESSION["logged_password"] = $_POST["password"];
            
    header('Location: page.php');
        }
        
    } else {
        echo(
    "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>
        <input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>"
    );
    }
    ?>
    page.php
    PHP Code:
    <?php
    session_start
    ();

    $password "test";

    if(
    $_SESSION["logged_password"] != $password) {
            
    session_destroy();
            
    header('Location: index.php');
    } else {
    ?>
    This is the page :)
    <?
    }
    ?>
    If you want to use multiple accounts and passwords, ask me tomorrow when im not tired

  3. #3
    Join Date
    Mar 2008
    Posts
    940
    Tokens
    75

    Default

    Quote Originally Posted by Jack120 View Post
    index.php
    PHP Code:
    <?php
    session_start
    ();

    $password "test";

    if(
    $_SESSION["logged_password"] == $password) {
            
    header('Location: page.php');
    }
    if(isset(
    $_POST["password"])) {

        if(
    $_POST["password"] == "") {
            echo(
    "<p align=\"center\"><font color=\"red\"><b>You didn't enter a password!</b><br>Please enter the correct password</font></p>");
        } elseif(
    $_POST["password"] != $password) {
            echo(
    "<p align=\"center\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>");
        } else {
            
    $_SESSION["logged_password"] = $_POST["password"];
            
    header('Location: page.php');
        }
        
    } else {
        echo(
    "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>
        <input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>"
    );
    }
    ?>
    page.php
    PHP Code:
    <?php
    session_start
    ();

    $password "test";

    if(
    $_SESSION["logged_password"] != $password) {
            
    session_destroy();
            
    header('Location: index.php');
    } else {
    ?>
    This is the page :)
    <?
    }
    ?>
    If you want to use multiple accounts and passwords, ask me tomorrow when im not tired
    Thanks Jack I was tired as well I kept getting one error, until I figured it out I had

    page.php and it was suppose to be misc/page.php Thank you!!


  4. #4
    Join Date
    Mar 2008
    Posts
    940
    Tokens
    75

    Default

    Will it forget the password when I clear my cache?


  5. #5
    Join Date
    Feb 2007
    Location
    Essex, England
    Posts
    1,392
    Tokens
    0

    Latest Awards:

    Default

    Yeah cos it's a session, I believe?

    And i thought you wanted a pw protected page, not two? :S


Posting Permissions

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