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
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 !

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! )

 

 

Link to comment
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.