Jump to content

simple login script


maxic0

Recommended Posts

Hi, im creating a simple login script and i dont have a problem yet but im wondering if there is a way that i can improve this bit of code, this is what i have for validating the fields...

 

<?php


if (!isset($username) {
echo "Username is a required field. <BR/> Please go <A HREF='register.php'>back</A> and fill it in.";

}

?>

 

I have four of these bits of code for validating the username, password, confirm password and email.

 

If there a way that i could use one if statement to validate all the fields then if one or more fields are left blank, it will say that they are required fields and say what ones they have missed out?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/46910-simple-login-script/
Share on other sites

no... each one needs to be validated seperatly...

if(empty($_POST[username]) echo "Username is a required field. <BR/> Please go <A HREF='register.php'>back</A> and fill it in.";
elseif(empty($_POST[password]) echo "Password is a required field. <BR/> Please go <A HREF='register.php'>back</A> and fill it in.";
elseif(empty($_POST[email]) echo "Email is a required field. <BR/> Please go <A HREF='register.php'>back</A> and fill it in.";

and so on :-)

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

personally... i prefer the less specific ones...

 

$username=addslashes(strip_tags($_POST[username]));
$password=md5($_POST[username]);
$query=mysql_query("SELECT * FROM `accounts` WHERE `username`='$username' AND `password`='$password' LIMIT 1");
$row=mysql_fetch_array($query);
if(empty($row)){
$_SESSION[error]='Invalid username/password';
redirect();
}else{
$_SESSION[user]=$row;
redirect();
}

Link to comment
https://forums.phpfreaks.com/topic/46910-simple-login-script/#findComment-228716
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.