Question: Merge these two files into one php file (below) PROMPT: Write a PHP file that will output a form containing 3 fields: username, password and

Merge these two files into one php file (below)

PROMPT:

Write a PHP file that will output a form containing 3 fields: username, password and Remember me! checkbox. Upon submission of the form, the code should check against MySQL table to see whether the username/password pair was correct. If so, display a welcome message and save a cookie that identifies the user to the server. On further visits to the page, the user should appear logged in, even if the browser has been closed; If not, display the message Invalid username or password followed by the same login form. Once again, there should only be one PHP file, and you should redirect to the same place after submitting. The output should be one of three options:

The login form.

The invalid message and the login form, if failed login.

The welcome message containing a Log Out button, if successful login.

When user clicks Log out button, remove the cookie so that the user is logged out. Clicking the button should redirect the user to the same page, which now shows a login form.

-----------login.php----------

Login Welcome

if(isset($_POST["logout"])){ header('Location:index.php'); }

------------index.php----------------

Login Form

Username: Password: Remember Me

while($row=mysql_fetch_array($result)) { $user=$row['USERNAME']; $password=$row['PASSWORD']; } $num=mysql_num_rows($result); for($i=1;$i<=$num; $i++){

if($username == $user && $password==$password) { if(isset($_POST['rememberme'])) {

setcookie('user',$_POST['user'],time()+ 60,); }else{ setcookie('user',$_POST['user'],false); } header('Location:login.php');

else{ echo("You must be logged in."); header("Location: index.php"); } } }

login.php ?>

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!