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