Jump to content
xisto Community
maddog39

[php]password Protect W/o Db A good php tutorial

Recommended Posts

Hello all,

 

I found this script actually on another website. But I modded it and added some things. Heres the code and stuff.

 

Open a new file in your text editor and paste in this code.

<?php{echo '<form name='pp' method='post' action='check.php'>Username:<input type='text' name='user' value=''><br>Password:<input type='password' name='pass' value=''><br><input type='submit' value='Login'></form>';}?>
Name this file login.php

 

Now open another new file in your text editor and paste in this code.

<?php// Change 'YourUsername' to whatever you want.if ($_POST['user'] == "YourUsername") {// Change 'YourURL' to the directory to forward to.echo "<meta http-equiv='refresh' content='0;URL=YourURL'>";}else {header("Location: error.php");}// Change 'YourPassword' to whatever you want.if ($_POST['pass'] == "YourPassword") {// Change 'YourURL' to the directory to forward to.echo "<meta http-equiv='refresh' content='0;URL=YourURL'>";}else {header("Location: error.php");}?>
Name this file check.php

 

For the last file, open up another new file in your text editor and paste in this code.

<?phpecho "I am sorry, you have entered the username or password inccorectly. You are now being redirected.";echo "<meta http-equiv='refresh' content='2;URL=login.php'>";?>
Name this file error.php. Then upload these to your server and try them out. Its an easy way to password protect directories on a webserver. :D

 

Demo: CLICK HERE

Deno User: test

Demo Pass: test

Edited by maddog39 (see edit history)

Share this post


Link to post
Share on other sites

Looky here. I setup a demo for you guys, the user is test and the pass is test. Try it it works. Plus I dont know what you mean by vailidate it. Anyway I am going to clean up the code a little bit.

Share this post


Link to post
Share on other sites

Your welcome, I think I have fixed all of the bugs in it. Just tell if there are anymore. I have been testing and changing it like all night. ;)

Share this post


Link to post
Share on other sites

I don't get you people and your exact code. Surely you've forgot a doctype once. Besides, it does work. Just because that stoopid W3 says it doesn't, doesn't mean the php won't work.God I hate W3

Share this post


Link to post
Share on other sites

No if you want registered members than a MySQL database IS required. There is not possible way to do without it as far as I know. ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.