CS 337 - Web Programming - Homework Assignment 5

This assignment is worth a total of 100 points.

This assignment will focus on some of the basics of the PHP programming language.

Resource Files

The files you will need to complete this assignment are located in this files folder.

Problem 0: Environment Setup 10 points

This assignment will require that you have access to a PHP environment of some type. While you can use whatever PHP environment you wish for development and testing, you will be graded on the performance of your code on the AWS Virtual Machines set up for you for the class.

Specifics of the AWS Virtual Machines:

Create a new html file setup.php and place it inside your html folder on your class VM. It should be accessible by going to http://xx.xx.xx.xx/setup.php where the IP address is the current one assigned to your VM. The contents of the file should just contain your name, and the following PHP code:

echo time();

Screenshot of Problem 0 solution
Your page should look similar to the above image, and be accessible when we turn on your VM for grading.

Problem 1: 50 points

There are two PHP files given to you for this problem: problem1.php and problem1_library.php. Your task will be to modify problem1_library.php and add various functions to it that will be called from problem1.php. You may want to modify problem1.php as you work, to comment out various function calls before you're ready for them, but we will use a new copy of the file when grading your work.

As a starting point, you are given one function, stringCat() as an example. You can see how this function is called from within problem1.php. You will create a total of eight more functions, and one new PHP class in the problem1_library.php file.

The various function calls inside of problem1.php are commented out initially. As you begin to work on each part, un-comment the appropriate function calls within problem1.php

Part a) Error Reporting

You may not know what the current error reporting levels are set at for your environment. For this part create a new function setErrorLevel() that takes no arguments. Make sure that the error reporting levels include only the following items:

Your function will be called first to set the levels, then the current error reporting levels will be printed to the screen.

Part b) String Cleanup

Create a new function named myStringCleanup which takes a single string argument. Do the following to the incoming string, and return the result:

Part c) Odd or Even

Create a new function named oddEven which takes a single numerical argument. Determine if the number is odd or even, and return either the string "odd" or the string "even" for each case.

Part d) Build an Array

Create a new function named buildArray which takes four arguments. Take these four arguments and create an array with them. Return your newly created array.

Part e) Read a Local File

In the files folder there is a text file: external_file.txt. Create a function called readLocalFile that takes no arguments. This function should do the following:

Part f) Server Software

Create a new function serverSoftware which takes no arguments. In this function, determine what sort of server software the current PHP environment is running in. Return this as a string. Note that your server software string may differ from the one in the screenshot below. As long as its close that's fine. The one in my screenshot is taken from the AWS Virtual Machines set up for the class.

Part g) Objects

This part is a little more involved. You will first need to flesh out a PHP Class named mySimpleClass. The skeleton of the class is given to you. You will need to do the following within the class:

Create a new function makeObject which takes one argument, a secret string. In this function, do the following:

Part h) Data Types

Create a new function getDatatype which takes one argument. In this function, determine the PHP Data Type, and return it as a string.

Final Page

Once you have all the parts finished, your page should look something like the following screenshot. There may be minor differences in parts f and g, but the others should look the same.

Screenshot of Problem 1 solution
Final Image - Click for larger view

Problem 2: Basic PHP Page - 10 points

For this problem you will create a simple PHP Web Page, and add a small bit of server side logic to it.

In the files folder is a file named problem2.php. It doesn't have much in it to start. There are two HTML comments in the file which direct you where to place a bit of server side logic.

Part a) File Include

Include a header file in the problem2.php file. There is an external file named header.html which contains an HTML fragment. Include this file in the main problem2.php file using PHP.

Part a) Current Date

Echo the current day and date to the page when the page is viewed. The format for the date is given in the following screenshot. You will have to research the correct syntax for the date() function from the PHP Documentation

Screenshot of Problem 2 solution
Final Image - Click for larger view

Problem 3: Forms - 30 points

For this problem, you will create a Contact page, and add an HTML form to it. You will also create a new PHP script to echo the form contents.

Sample Form Image
Example Form - Click for larger view
Form submission result
Example form.php result page - Click for larger view

Homework Submission

You should create a folder holding your files, and zip it up for submission. Name your folder and zip file something descriptive like Your-Name-HW5.zip. Please make a folder with your files in it, and zip up the folder. Do not select all the files and zip them up. Your name is not Mark Fischer (that's my name!). :)

File List

Homeworks Zip files will be submitted to D2L, in the "Assignment 5" dropbox.

You must also have the following pages available on your class VM

Server Web Pages