Question: I have a separate PHP file and an HTML file that I used to make a long in page with set usernames and passwords. The

I have a separate PHP file and an HTML file that I used to make a long in page with set usernames and passwords. The assignnment is to now take both those files and combine them into one php script. AND use trim function to trim input AND use htmlspecial chars on input. Thank you.

Here is the original HTML script

Lab 3

Please Login Below

Username:

Password:

And here is the original PHP script.

//-----------------------------------------------------------Part 1-----------------------------------------------------------------------------

$loggedin = false;

$passwordIn = true;

$usernameIn = true;

$validUsername = true;

$users = array("elliez" => "23Seventeen23", "junk0" => "password1", "busyBee" => "pass20word", "computerGal" => "pass30word",

"compGuy" => "mypass2309", "expertComp" => "60your78", "smartone" => "78y68pal", "johndoe" => "pass4567",

"johndoe3" => "pass2100", "johndoe67" => "pass2099");

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

{

foreach($users as $k => $v)

{

if(empty($_POST['username']))

{

$usernameIn = false;

}

if(empty($_POST['password']))

{

$passwordIn = false;

}

elseif($_POST['username'] == $k and $_POST['password'] == $v)

{

$loggedin = true;

}

}

if($loggedin == true)

{

echo "You have succesfully logged in!";

}

elseif($loggedin == false and $passwordIn == true and $usernameIn == true)

{

echo "Sorry, wrong information has been entered!";

}

if($usernameIn == false)

{

echo "Username is required. ";

}

if($passwordIn == false)

{

echo "Password is required. ";

}

}

//---------------------------------------------------------------Part 2-------------------------------------------------------------------------

if(isset($_POST['register']))

{

foreach($users as $k => $v)

{

if(empty($_POST['username']))

{

$usernameIn = false;

}

if(empty($_POST['password']))

{

$passwordIn = false;

}

if($_POST['username'] == $k)

{

$validUsername = false;

}

}

if($usernameIn == false)

{

echo "Username is required. ";

}

if($passwordIn == false)

{

echo "Password is required. ";

}

if($validUsername == true and $usernameIn == true and $passwordIn == true)

{

echo "You have chosen a valid username.";

}

elseif($validUsername == false)

{

echo "Sorry, that username is taken.";

}

}

?>

This is the example my professor provided

Form and Processing function putForm($errors) { echo "

First Name: "; echo "".$errors['Fname']." "; echo "Submit:"; } ?>

$errorList = array('Fname' => ""); if (!isset($_POST['submit'])) putForm($errorList); else if ($_POST['Fname']== NULL){ $errorList['Fname'] = "PLEASE PUT IN PROPER NAME"; putForm($errorList); } else { ?

THANK YOU!!! A positive review will be given if completed. Thank you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!