FatalSpirit Posted June 18, 2006 Share Posted June 18, 2006 Hello everyone!Can someone tell me how to make a simple login on my index page to protect all my other pages? I dont want there to be register function, but just a account text field, a password field, and a submit button. I just want it to have one set password and account. I am making this for my family website, so that random people wont be able to see my emberassing pictures, but only my grandparents which are back in Russia. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/12283-simple-login/ Share on other sites More sharing options...
habook2 Posted June 18, 2006 Share Posted June 18, 2006 This is what you need to put on the main page for you to log in on:[code]<form action="http://whateverwhatever.com/login.php" method="post">Username:<input type=text name="username"><br>Password:<input type=password name="password"><br><input type=submit value="Log in"></form>[/code]Then you need to create a seperate page, called [a href=\"http://www.whateverwhatever.com/login.php\" target=\"_blank\"]http://www.whateverwhatever.com/login.php[/a] with the following code:[code]<?php $name = $_POST['username']; $pass = $_POST['password']; $realuser = REAL USERNAME HERE; $realpass = REAL PASSWORD HERE; if($name == $realuser && $pass == $realpass){echo "Click <a href=URL TO PROTECTED PAGES>here</a> to go to the protected pages.";} else {die("Login Failed");}?>[/code]Also, if I screwed this up somehow, someone please correct me. Quote Link to comment https://forums.phpfreaks.com/topic/12283-simple-login/#findComment-46931 Share on other sites More sharing options...
JP128 Posted June 18, 2006 Share Posted June 18, 2006 type this in on all of the pages that you want to protect...include "config.php";authUser();then have a page called config.php and have this in it...<?php$user= $_POST['user'];$pass = $_POST['pass']$realUser = ""; // what you want your user name to be$realPass = ""; // what you want your password to be.function authUser(){if($user == $realUser){if($pass == $realPass){?><script language="javascript">location.href="index.php";</script><?php}}else {echo"<form method=POST action=\"index.php\"><input type=text name=\"user\"><input type=password name=\"pass\"><input type=\"submit\" value=\"Auth\"></form>}}?> Quote Link to comment https://forums.phpfreaks.com/topic/12283-simple-login/#findComment-46932 Share on other sites More sharing options...
FatalSpirit Posted June 18, 2006 Author Share Posted June 18, 2006 Thanks so much, both of you! I will try them both. Quote Link to comment https://forums.phpfreaks.com/topic/12283-simple-login/#findComment-47011 Share on other sites More sharing options...
Holmen Posted June 18, 2006 Share Posted June 18, 2006 Ok, but how to I create an account for it? Quote Link to comment https://forums.phpfreaks.com/topic/12283-simple-login/#findComment-47100 Share on other sites More sharing options...
Holmen Posted June 19, 2006 Share Posted June 19, 2006 ah, find it. Quote Link to comment https://forums.phpfreaks.com/topic/12283-simple-login/#findComment-47243 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.