Jump to content

Simple Login


FatalSpirit

Recommended Posts

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!
Link to comment
https://forums.phpfreaks.com/topic/12283-simple-login/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/12283-simple-login/#findComment-46931
Share on other sites

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>
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/12283-simple-login/#findComment-46932
Share on other sites

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.