Jump to content

basic login authentication help


AlanB09

Recommended Posts

hi there, im new to PHP and this is my attempt at a very basic login authentication.  i can get the first 'IF' to run, but the else if doesnt seem to want to work LOL.  i wonder if any one can help with this please?

 

i will post the form first.. .. this is called test.

 

<html>

<head>

<title> More on Variables</title>

</head>

<body>

<form id="login" method="POST" action="logins.php"><br />

Username: <input type="text" name="user" value="user" /><br />

Password: <input type="password" name="password"" /><br />

<input type="submit" value="submit" name="Submit" /><br />

</form>

 

</body>

</html>

 

and now the script.. in a file called logins.php

 

<html>

<body>

<?php

// Retrieves the username posted in the form and sets the password

$password="Enter";

$username=$_POST['user'];

 

if($username == "Alan" AND $password == "Enter"){

print("Welcome back $username");

}

else if($_POST['user'] == "Mel" AND $password == "Laura"){

print("Access Granted, Hiya Pal");

}

else {

print("Access Denied");

}

 

?>

</body>

</html>

 

once again, thank you for any help :) please keep very basic as i'm just beginning to get to grips with things. 

Link to comment
https://forums.phpfreaks.com/topic/184936-basic-login-authentication-help/
Share on other sites

$password="Enter";

You made it = Enter, so Mel can never login....

it needs to = $_POST['password'];

$password=$_POST['password'];

 

thank you very much :) .. simple logic, i cant believe i didnt see that... i have to say every time i feel like im getting somewhere, i get confused and have to start all over again lol !

 

lol i know this is going to be really really useful which is why ive kept going but honestly ive been banging my head off a wall lmao !! i take it a login script like that wouldnt be very secure though ?

 

You may want to use

$password = mysql_real_escape_string($_POST['password']);

To sanitize the input against SQL injections (if you were to have a database, per say.)

 

The next step I guess that you'd want to learn is sessions, which allow a logged in person to persist logged in, sessions are pretty simple.

phpfan and oni thank you this is exactly what i need.. a sense of direction!

ive gone over variables, operators, etc etc about 100 times, but i need direction lol!

simple login in is the start.. next is how to redirect it to my webpage once logged in :)

and im thinking i may need to write a register script lmao !! (uhoooh sql here i come too! )

 

 

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.