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 Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/ 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 Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701817 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? Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701820 Share on other sites More sharing options...
laPistola Posted November 29, 2008 Share Posted November 29, 2008 using sessions would be your best bet Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701822 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? Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701823 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 Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701826 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Yes I do. Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701836 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Anyone able to help? Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701845 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 Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701862 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? Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701880 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. Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701894 Share on other sites More sharing options...
Akenatehm Posted November 29, 2008 Author Share Posted November 29, 2008 Anyone know? Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701910 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. Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701921 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). Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701925 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? Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701927 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? Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701928 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. Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701935 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? Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701938 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. Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701939 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 Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701945 Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Sweet. Thanks Guys. Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-701956 Share on other sites More sharing options...
mapleleaf Posted December 1, 2008 Share Posted December 1, 2008 tizag.com is also a good site Link to comment https://forums.phpfreaks.com/topic/134775-password-protecting-html-pages-with-php/#findComment-702721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.