Jump to content

Login Script


gabasc09

Recommended Posts


<?php

$set_username = 'user';
$set_password = 'pass';

if(isset($_POST['submit'])){


$username = $_POST['username'];
$password = $_POST['password'];

if(empty($username)){
	$error['username'] = 1;
} else {
	if($username == $set_username){
		$error['username'] = 0;
	} else {
		$error['username'] = 2;
	}
}

if(empty($password)){
	$error['password'] = 1;
} else {
	if($password == $set_password){
		$error['password'] = 0;
	} else {
		$error['password'] = 2;
			}
}


if($error['username'] == 0 && $error['password'] == 0){
	session_start();
}

}

?>

<form method="post">
<table>
	<tr>
		<td>Username</td>
		<td><input type="text" name="username" value="<?php if($error['username'] == 0 && $error['password'] == 1 || $error['password'] == 2) {echo $username;} ?>" /></td>
		<td><?php if($error['username'] == 1){ echo 'Username is not entered';} elseif($error['username'] == 2) {echo 'Username is invalid';}?></td>
		</tr>
	<tr>
		<td>Password</td>
		<td><input type="password" name="password" /></td>
		<td><?php if($error['password'] == 1) { echo 'Password is not entered';} elseif($error['password'] == 2) { echo 'Password is invalid' ;} ?></td>
		</tr>
	<tr>
		<td></td>
		<td><input type="submit" name="submit" />
		</tr>
	</table>
</form>

 

I am unsure why im getting PHP notices. And may i ask if my method is conventional and good? If not please state why :\

Link to comment
https://forums.phpfreaks.com/topic/171120-login-script/
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.