Akenatehm Posted November 29, 2008 Share Posted November 29, 2008 Hey Guys, I was just wondering if it was possible to Password Protect HTML Pages with PHP. I need to secure my Administration Panel Sites. Any information or help would be greatly appreciated. Akenatehm Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 29, 2008 Share Posted November 29, 2008 Have you considered using htaccess to provide password protection? http://www.javascriptkit.com/howto/htaccess3.shtml Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 I want the Login to come from a MySQL Database so I can have multiple admins. Is this possible with htaccess? Quote Link to comment Share on other sites More sharing options...
laPistola Posted November 29, 2008 Share Posted November 29, 2008 using sessions would be your best bet Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Could you give me any direction in that? Would this: http://www.scripts.com/viewscript/admin-login-only/4609/ be a good one? Quote Link to comment Share on other sites More sharing options...
aircooled57 Posted November 29, 2008 Share Posted November 29, 2008 i presume you already have the database setup with the username and password or just the password stored in a table ? can offer more help with a little clarification of your situation Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Yes I do. Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Anyone able to help? Quote Link to comment Share on other sites More sharing options...
chronister Posted November 29, 2008 Share Posted November 29, 2008 Here are the basics.... you have not given us much to work with. <?php if(!isset($_SESSION['loggedIn'])) // check for a logged in session var { header('Location:/login.php'); // if it is not found, then jump to the login page } ?> On login.php, create a form with a user name and password boxes in it. login.php <?php if(isset($_POST['nameOfLoginButton'])) { // we are going to process the login.... // initiate connection to the database // once we have a connection to the db..... $usernameField = $_POST['userName']; $encryptedPassword = md5($_POST['password']); // I assume your using the md5 hash function to store passwords in the db. $result = mysql_query("SELECT * FROM usersTable WHERE usernameField = '$userName' && password = '$encryptedPassword'"); if(mysql_num_rows($result) > 0) { // a row was returned and our user entered valid credentials, so log them in $_SESSION['username'] = $usernameField; $_SESSION['loggedIn'] = true; } } ?> Make sure to have session_start() at the beginning of each page you wish to have protected. use the first if() statement on every page you want to password protect. Let us know if you have questions... This is not intended for you to be a copy / paste solution... but to give you the basics. It should be beefed up to protect the variables and clean the sql query before running it. Nate Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Thanks a ton man for your effort in helping me. Just one question, can the first little PHP script be inserted into an HTML page? and do I need to add the connection details myself to the second php script? Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Also.... is there a way to decrypt with php so that the data can be read in a SWF Flash Login. Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Anyone know? Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted November 29, 2008 Share Posted November 29, 2008 can the first little PHP script be inserted into an HTML page? Yes but be sure to put session_start(); before anything else. is there a way to decrypt with php so that the data can be read in a SWF Flash Login. This kind of password set up is one way. Flash is be able to use php to make the password check. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 29, 2008 Share Posted November 29, 2008 You need to rename your .html files to .php in order for php code to work (unless you have your webhost to parse .html as php). Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 can the first little PHP script be inserted into an HTML page? Yes but be sure to put session_start(); before anything else. Could you explain how to do this a bit better please? is there a way to decrypt with php so that the data can be read in a SWF Flash Login. This kind of password set up is one way. Flash is be able to use php to make the password check. Could you maybe state the other ways and/or explain how to do them please and how i would go about setting this up? Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 You need to rename your .html files to .php in order for php code to work (unless you have your webhost to parse .html as php). By renaming them, would it make much difference? Quote Link to comment Share on other sites More sharing options...
revraz Posted November 29, 2008 Share Posted November 29, 2008 Difference in what way? It won't work if you don't. Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Ok then lol. But It won't change anything with the HTML in the files though will it? Quote Link to comment Share on other sites More sharing options...
revraz Posted November 29, 2008 Share Posted November 29, 2008 Ranaming a file won't change the HTML. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted November 29, 2008 Share Posted November 29, 2008 Take a look at this tutorial. It'll help you get started with what you want http://www.php-mysql-tutorial.com/user-authentication/database.php Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Sweet. Thanks Guys. Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted December 1, 2008 Share Posted December 1, 2008 tizag.com is also a good site Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.