SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Password Checkpoints

    Hey everyone!

    I want to make 'checkpoints' where users must enter a password to proceed to the next page. I would like it so if they enter the right password they will be redirected to a new page and if they enter a wrong password they will be prompted to try again.

    If this is unclear please ask and I will try to specify a little further.

    I am sort of new to this so any help is appreciated!

    Thanks in advance!

  2. #2
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It really depends on how you want to do it. You can use the core session handler or use a database session control or if you don't want to use a database you can use file storage for authenticating users.

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have access to MySQL so I'd like to use that....or whatever is easier.

    Can anyone give me the code or find a site that lists it?

    Thanks!

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Welcome to the forums.

    For each passworded page, set a PHP variable for the password that's needed to access the page. Then, use the following code:
    PHP Code:
    <?
    $pass 
    "abc123"//the password
    if($_POST['pass'] == $pass){
       
    header("location: page2.php"); //redirected page
    }else{
       
    $wrongPass true;
    }
    ?>
    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
    Password: <input type="password" name="pass" />
    <? if($wrongPass == true){
       echo 
    "Wrong Password!";
    }
    ?>
    <input type="submit" />
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the welcome!

    what I mean is, I'm not really password-protecting a page I'm just making the user enter a password to lead them to a page....

    Sorry for being unclear...

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's alright
    That code should do what you want - it errors if the password is wrong, and it redirects the page if it's correct.

    If you want to go into different usernames and password, there are plenty of tutorials available through google.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Welcome to the forums.

    For each passworded page, set a PHP variable for the password that's needed to access the page. Then, use the following code:
    PHP Code:
    <?
    $pass 
    "abc123"//the password
    if($_POST['pass'] == $pass){
       
    header("location: page2.php"); //redirected page
    }else{
       
    $wrongPass true;
    }
    ?>
    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
    Password: <input type="password" name="pass" />
    <? if($wrongPass == true){
       echo 
    "Wrong Password!";
    }
    ?>
    <input type="submit" />
    That's not a very good example, teaching bad habits is never a good idea. You can't test a variable that may not even exist. That also does not offer any protection to the redirect page.

  8. #8
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lemme try making myself more clear:

    I want to have something like what you just showed me, but i wold like to use MySQl to maybe make it a little more secure? What I will be doing is running a little contest and having people complete steps. After they complete a step, they will be given a password which they must enter to begin the next step. So its really just a right password>next step, wrong password>try again kind of thing...

  9. #9
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    GR
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  10. #10
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It not really a session because they don't log in to anything....its just away to let a user get to a specific url if they enter the right password.

  11. #11
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can you explain a bit further on what you're trying to accomplish?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  12. #12
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure! I hope this helps...

    I want to have a 'on-site plot' where visitors have to solve puzzles to get passwords. They must solve the puzzle to get to the next puzzle because they must enter a password into a form. The form will either prompt them to re-enter the password or lead them to the url where the next puzzle is located.

  13. #13
    SitePoint Zealot detzX's Avatar
    Join Date
    Oct 2006
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then what arkinstall entered would work.
    www.invoicejournal.com - Invoice clients for Free

  14. #14
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, I tried the code but it didnt really work....maybe I did it wrong o_O

    When I clicked the submit biutton, nothing happened....

  15. #15
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh! I just noticed that arkinstall said:
    For each passworded page, set a PHP variable for the password that's needed to access the page. Then, use the following code:
    Say the page I wanted to access with the right password is "good.php"
    How would I do that?

    Thanks!


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
  •