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
https://forums.phpfreaks.com/topic/46491-solved-simple-password-protected-page/
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.

...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>
             ";
?>

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. 

 

=)

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){

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.