Jump to content

[SOLVED] Simple password protected page?


PirateBagel

Recommended Posts

I only need to secure one page, and security isnt that big of an issue.

 

All im looking for is a username/password prompt (I only need one logon)

 

I don't want to deal with mySQL databases, adding, tracking, blah blah blah - Just a login.

 

 

I've been searching and everything I find isnt what I'm looking for, I know this cannot be too much code.

 

Thanks,

 

Adam

 

 

Link to comment
Share on other sites

if you don't want to deal with a database, the only way to authenticate a user is on the server level. this should be easy to implement, altho it would be more difficult if you are using a hosting company to host your site, but still do-able.

Link to comment
Share on other sites

...or you can hard-code the passwords in your script.

<?php
        $passwords = array('dirka', 'poop', 'admin', 'reefer');

        $bool = false;
        if(isset($_POST)){
                foreach($passwords as $password){
                        if($_POST['password'] == $password){ $bool = true; }
                }
                if($bool = true){ header(Location: www.yoursite.com/successfulLogin.php); }
                else{ echo "You have not entered the correct password. Please try again."; }
        }

        echo "
                <form action=\"\" method=\"post\">
                enter password:<input type=\"password\" name=\"password\">
                <input type=\"submit\" value=\"Submit\">
                </form>
             ";
?>

Link to comment
Share on other sites

The only problem with boo's is that one, anyone can access successful login. two, it will always send them to that page due to $bool = true, it is assigning it to true which is always true =)

 

That script you posted is a good one. Another option would be .htaccess with .htpasswd, but if that script works for you, great. 

 

=)

Link to comment
Share on other sites

The only problem with boo's is that one, anyone can access successful login. two, it will always send them to that page due to $bool = true, it is assigning it to true which is always true =)

 

That script you posted is a good one. Another option would be .htaccess with .htpasswd, but if that script works for you, great. 

 

=)

 

say what now? :)

 

EDIT: OH did you mean this part?

if($bool == true){

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.