Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 4: Project As you know, the last exercise of each assignment is continu

ID: 3817423 • Letter: E

Question

Exercise 4: Project

As you know, the last exercise of each assignment is continued from assignment to assignment and will have the goal of building a website by the end of this course. (Note: since this assignment introduces PHP into the project, it is likely that some of your web pages will have to have their extensions changed from .html to .php).

Nancy’s Apartment Search Website Running Problem – Version 3 This version requires HTML, CSS, JS and PHP. No XML is required.

1) Create a template for your entire site such that you define the header and footer once and include them in each page of the site. This should be done using PHP. The following is just as a reminder of what the header and footer should contain:

Header: It should include the name of your service and a logo/picture. Clicking on the logo/picture should take you back to the home page. It should also display the current date and time. The Time should automatically refresh every second.

Footer: This should appear at the bottom of all your pages. Give it a distinct background color and include links to a Privacy/Disclaimer Statement which can either appear in the content area of the site or in an alert or confirm box. It should display a message promising users that their information will not be sold or misused, and protects the website builder from any incorrect information.

2) You will manage 2 text files which will reside on the server.

a. A login file which will contain username and passwords. This file will be consulted when a user is logging in. Each field should be separated by colon (:) and each user info is in one line. For example if I have a file with 3 accounts, the file will look like so: user1:pass1 user2:pass2 user3:pass3

b. An available apartment information file that will store the information about address, type, amenities, pet info. Design your own format and field name for search.

3) Functionality of your site: Add the following functions to your site:

Search: enter some search criteria and submit the query to a server site PHP program. This PHP program can search in the available apartment information file and find the matching apartments. Please notice that you can have none or multiple matchings.

Login/Create New Account:

o Add a login button at the top-right corner of the search page.

o When a user clicks on this button, a login page loads into the content area with text fields for a username and one for a password as well as a login button. Below the login button, you can show a description of the allowed formats for usernames and passwords. A username can contain letters (both upper and lower case) and digits only. A password must be at least 4 characters long (characters are to be letters and digits only), have at least one letter and at least one digit. Before sending this information to the server make sure that the entered username and password satisfy the format criteria just listed.

o A user can input a username and a password on the login page. If the username and the password is a match verified by a PHP program against the log in file, redirect the user to the search page with “welcome, username” at the top-right corner (besides the login button). If the username exists and the password is not a match verified by a PHP program against the log in file, stay on the login page and show “invalid login” before the login button and allow the user to re-enter inputs. If the username does not exist, write this new pair to the login file following the format specified in bullet 2 a) and return a new page to confirm that the account was successfully created and display a button to redirect the user to the search page.

Connect the search page and the account login: if the user has logged in, show the full search results – types, street address, price. If the user does not login, the search results include only the area information, not the street address and a button “login to show the address” besides each result item. User can click the button to login. You do not need to cache the search results. After the login, the search starts again.

Explanation / Answer

I am providing you a basic template for the complete project by answering Q1 from this project. Please go through the complete answer and build your strategy to develop the project further in order to learn it.

1. Create a template for your entire site such that you define the header and footer once and include them in each page of the site.

File Structure: All pages should be in a folder. To understand:

-- we name our homepage as index.php

-- Header code should be saved in header.php

-- footer code should be saved in footer.php

We will use the 'include' statement in PHP to include common header and footer files on each page on the website as shown below.

INDEX.PHP:

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<?php include 'header.php';?>
<!-- homepage content -->
<?php include 'footer.php';?>
</body>
</html>

HEADER.PHP:

<a href="index.php"><img src="logo.jpg"></a>
<h1>Write the name of service here</h1>
<p id="time"><!--this is where time will appear--></p>
<script type="text/javascript">
   function updateClock() {
document.getElementById('time').innerHTML = [date, time].join(' / '); /*creates time */
}
setInterval(updateClock, 1000); /* updates time every second */
</script>

FOOTER.PHP

<div>
   <a href="#">Privacy Statement/ Disclaimer</a>
</div>
<script type="text/javascript">
   function myFunction() {
    alert("Your information will not be shared or misused and protects the website builder from any incorrect information.");
}
</script>