COSC260 Web Programming Assignment Problem

Assignment Help PHP Web Programming
Reference no: EM132380738

COSC260 Assignment: Server-Side Quiz Application

Your task is to develop a basic server-side user registration service in PHP. This service will operate in a very similar manner to the one your client-side application interacted with in Assignment 2.

Upon receiving a HTTP POST request, with the fields name, age, email and (optionally)
phone, your service should return a user ID (randomly generated) to the client.

All requests must be checked for invalid input, and if found, an error message and appropriate HTTP status code must be returned. All successful requests should be written to a file, in JSON format.

There are 5 components to the assignment:
A) Error response function
B) Request validation
C) Data validation
D) User ID
E) Database

Starter Code
You are provided with starter code, both for your server-side application, and for a client- side testing application. Please use the PHP starter code provided, as you will be required to use some of the pre-existing variables present. The client-side application is used to test your server-side code, as it allows you to make a POST request using a form, with output displayed. Your submission for Assignment 3 will contain server-side code only.
Deploying Your Code
This is also covered in Tutorial 7 (Week 10)

In order to test your PHP code, you can either run your own web server, or use Turing which has everything you need installed. To use Turing for web development, simply make a folder (if it doesn't already exist) in your Turing home directory named public_html

The UNIX permissions on your PHP files MUST allow for other users to read, since the web server process is running on Turing as a different user. You can enable an autoindex file listing by giving other users execute permissions on the folder. (+x on a directory allows for listing of folder contents)

You can do this via the command line:
chmod a+r ~/public_html/myfile.php
Allow all to read the file myfile.php

chmod a+x ~/public_html
Allow all to execute the folder ~/public_html

Or by using the turing desktop GUI (process is the same for execute permissions):
- Right click on the file you want to modify -> Properties
- Go to Permissions tab and change the Others setting to Read only

Testing Your Service

You are provided with a test client (HTML, CSS, and JS with jQuery) which allows you to submit data to your web server, using a web form: you can use this to test your server-side application. The client will display responses from the server both on the page and in the JS console. To use this testing client, you will need to change the url variable at the start of the submit.js file to the address of your web server.

If you wish to use this client for testing, please familiarize yourself with the code, and feel free to edit it if needed.

Make sure to also perform your own testing and not rely solely on the provided client. You should also use the ‘network' and ‘console' tabs of your browser developer tools to inspect requests and responses. It is highly recommended that you use a browser addon, such as Advanced Rest Client or RESTED, or use cURL to script your own tests. You could also write your own client-side tester using HTML, CSS, and JS!

A) Error Response

Implement a PHP function that returns a HTTP status code along with a custom message in the header and body of the response to the client. This function will be needed for all subsequent sections and should be used when an error occurs (invalid input, wrong request type etc.). The function must set the appropriate HTTP header AND provide the message in the response body in JSON format.

A good function definition would look like: send_error($code, $message)

The function should take 2 input parameters:
(Integer) $code will be the HTTP status code to return. (String) $message will be a custom message text

The code variable contains a value which is also key in the $responses array provided. This array maps integer codes with their appropriate reason text. Make sure to use this array! You can get the server protocol from the $_SERVER superglobal.

The header should be of the form:
$PROTOCOL $CODE - $REASON

The response body should contain a valid JSON object of the form:

Where:
$PROTOCOL = HTTP Protocol used (e.g. HTTP/1.1)
$CODE = HTTP Status Code (e.g. 400)
$REASON = HTTP Status Code Reason (e.g. "Bad Request")
$MESSAGE = Custom message (e.g. "Age must be between 13-130")

Example Header:
HTTP/1.1 400 - Bad Request: Age must be between 13-130

Example Body:

NOTE: You cannot use the http_response_code() function in PHP for this as it does not allow for custom reason messages.

B) Request Validation
Requests must be validated to ensure they are correct for the service. This means the request must be of the right type and must contain valid data.
All incoming requests must meet the following criteria:
1) The request must be POST: No other request types are accepted.
2) The request must contain POST data: An empty body is invalid
3) All required fields must be present in the POST data: name, age, and email
a. Note the POST data may also include an optional field: phone

If any of the criteria above is not met, an appropriate HTTP status code must be returned to the client. The body of the response must also contain the HTTP status code and reason, along with a custom error message. You must use your error response function from Part A.

C) Data Validation
All user data must be validated on the server-side, to ensure it is safe, complete, and correct. Even though client-side validation may have been conducted, there is no guarantee that client-side code has not been modified, or even executed at all.

All incoming POST data for the service must be validated to meet the conditions below.

POST Field

Description

Validation Requirements

name

Name of the user

  • MUST be between 2 and 100 characters long
  • MUST only contain characters a-z (upper and lower case), - (hyphen), or ' (apostrophe)

age

Age in years

  • MUST be an integer value between 13-130

email

Email address

  • MUST be validated using either:

o The provided Regular Expression (See last page)

o An appropriate regex found online (must be credited with the URL at which you found it)

phone

Phone number (optional)

  • OPTIONAL: This field may be empty
  • MUST be exactly 10 characters long
  • MUST only contain digits (no letters or symbols)
  • MUST start with '04'

  1. If any of these validation requirements are not met, an appropriate error message should be returned, using your error response function from Part A. You may return the first error encountered, all present errors, or some other variation.

D) User ID
If all validation is successful, your service should return success response, and a randomly generated user ID. The response should contain a JSON object with the format:

The exact format of the user ID is up to you, but it must be randomly generated on the server.

E) Database
In a typical server-side application, once user data is validated it would then be written to a database. We will simulate a database by writing each successful request to a text file. For each request that passes validation, all received data should be written to file, in JSON format.

You must implement your "database" using PHP classes. An empty class file Database.php
has been provided in the class/ directory.

You must have a class property for each of the received fields: name, age, email, phone. Your class must implement the JsonSerializable interface and use this to write to the database file. This does mean that during the execution of your application, you will convert data from JSON (received from the client) to a Database object, then back to JSON for writing.

Note that there is no requirement to be able to programmatically read data back from your file, you only need to append the new data to the end.

Attachment:- Server-Side Quiz Application.rar

Reference no: EM132380738

Questions Cloud

Prepare journal entries to record the purchase and related : The building has an estimated life of 40 years and an estimated residual value of $5,000. Prepare journal entries to record the purchase.
Explain how societal issues influence international trade : Explain how societal issues influence international trade.
How should the company measure organizational performance : The best possible options for evaluating a strategic plan. How should the company measure organizational performance?
What is the primary reason for relying onthose controls : If the results of those tests are satisfactory, the auditor may thenrely on those controls. What is the primary reason for relying onthose controls ?
COSC260 Web Programming Assignment Problem : COSC260 Web Programming Assignment help and solution, University of New England, Assessment help - Develop a basic server-side user registration service in PHP
Describe a situation in which you felt a connection : First, describe a situation in which you felt a connection with someone who shared your own cultural background. Describe that feeling. What made you feel.
Calculate the value of ending inventory and cost of goods : Assume same facts as above except that Wholesaler uses a perpetual inventory system. Calculate the value of ending inventory and cost of goods sold for January.
Compare deming theory of profound knowledge : Compare Deming's Theory of Profound Knowledge and Crosby's Absolutes of Quality Management.
Analyze what you know of stan according to feminist : Analyze what you know of Stan according to Feminist, SFBT, and Narrative therapies. Through each lens, highlight the things you know about Stan that would be.

Reviews

Write a Review

PHP Web Programming Questions & Answers

  An array

Write a simple PHP program that prints the days of the week using three different methods: using plain HTML, using echo statements and using an array. Ensure correct documentation, indentation, var names etc.

  Create a very simple order system as a web application the

create a very simple order system as a web application. the application allows users to view the order and products

  Proper hypertext markup language and javascript structures

1.proper hypertext markup language html and javascript structures2.error-free3.all pages and images properly saved and

  Question 1 what type or types of business entityies do you

question 1. what type or types of business entityies do you recommend able baker charlie and delta create?question 2.

  For many years the acme company carried on business as a

for many years the acme company carried on business as a manufacturer of consumer products. in 1988 it embarked on

  Create an online parking system

To create an online PARKING system with php/mysql or any other coding language suitable and dissertation proposal

  Php script and then saves the form

Create a simple survey form that posts to a PHP script and then saves the form inputs to a file. The program should then respond with a display of the information contained in the file including the latest post

  Find the prime number and prepare the code in php

Create a function that checks if an integer n is a prime (returns true if the integer is prime and false otherwise). In the body of your page create a loop that uses this function to check and display all primes in a range from 1 to 100.

  Develop an envisioned methodology and design a research

develop an envisioned methodology and design a research topic based on the research problem purpose. then write a

  Create an xslt stylesheet that transforms the provided xml

Use the documents that are posted on share out. Many of them demonstrate very similar (or even the same) examples as what you are being ask to do for this assignment.

  Discuss the moral and economic implications involved in the

discuss the moral and economic implications involved in the movement.analyze each of the implications identified above

  Create a form that sends data to best_songs.php on a server

Create a form that sends data to best_songs.php on a server. The form should have a text box for your name and a collection of at least four checkboxes representing kinds of songs and a radio button to indicate whether the selected items are to be so..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd