Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.