Jump to content


Photo

Simple Login


  • Please log in to reply
5 replies to this topic

#1 FatalSpirit

FatalSpirit
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 18 June 2006 - 05:50 AM

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!

#2 habook2

habook2
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 18 June 2006 - 06:05 AM

This is what you need to put on the main page for you to log in on:
<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>

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:
<?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");}?>

Also, if I screwed this up somehow, someone please correct me.

#3 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 18 June 2006 - 06:14 AM

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


-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#4 FatalSpirit

FatalSpirit
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 18 June 2006 - 04:36 PM

Thanks so much, both of you! I will try them both.

#5 Holmen

Holmen
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 June 2006 - 08:34 PM

Ok, but how to I create an account for it?

#6 Holmen

Holmen
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 June 2006 - 09:49 AM

ah, find it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users