Bautista, Jeramie 200411360
Campos, Julius A 200413114
Instructor: Engr. Lorenzo B. Sta. Maria Jr.
Advance Topic to Internet Lab / CPE 520L / Monday 12 - 3

ADVANCE TOPIC TO INTERNET
a collection of Answers, Guide Questions Laboratory Experiments

 

Machine Exercises

FINALS

Machine Exercise 8

Machine Exercise 7

MIDTERM

Machine Exercise 6

Machine Exercise 5

Machine Exercise 4

PRELIM

Machine Exercise 3

Machine Exercise 2

Machine Exercise 1













 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

FINAL TERM MACHINE EXERCISES

Machine Exercise 8

Guide Questions:

1. Open register.php and input valid information on the form. This time, make the password and confirm password to be intentionally incorrect (they should not match) to test if the processing of comparison is working.
Does case-sensitivity apply for the password in the sample script?

ANSWERS: YES, Case sensitivity applies, The PHP script returns an error message that you need to confirm the password in order to proceed. The PHP script generates a test perfroming the comparison of the variable defined to the variable encoded in the password field and thus will produce a message regarding the confirmation of the password.

2. Write down a list of all the PHP built-in (internal) functions used in the sample program. Mention the function name, description/purpose, and how it is used in the example. (Note: Technically, echo is not really considered as a built-in function. This is why you are not required to use parentheses with it.)

ANSWERS:
A. empty() - Determine whether a variable is empty. It was used in the example as a condition checker for the email address and password of the registration form.

B. is_numeric() - finds whether a variable is a number or a numeric string. It is used in the example as a checker for the month, day and year of the birthdate.

C. strlen() - gets the length of the given string or in other words it counts the total number of characters in an entry. It is used in the example as a checker so that the inputted value in the year is equal to 4.

BACK TO TOP


Machine Exercise 7

Guide Questions:

1. Define each function below. Include a discussion on how each function is used in the sample program.

a. require() - is identical to include() except upon failure it will produce a fatal E_ERROR level error. The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).


b. define - function defines a constant, SYNTAX - define(name,value,case_insensitive)
Constants are much like variables, except for the following differences:

A constant's value cannot be changed after it is set
Constant names do not need a leading dollar sign ($)
Constants can be accessed regardless of scope
Constant values can only be strings and number


c. date - function formats a timestamp to a more readable date and time.

d. isset - a boolean, Determine whether a variable is set

e. empty - a boolean, Determine whether a variable is empty

2. Make a list of formats of the date function.


date("Y/m/d")
date("Y.m.d")
date("Y-m-d")

Here are the complete list in case you want a complete format.

DAYS
d - day of the month 2 digits (01-31)
j - day of the month (1-31)
D - 3 letter day (Mon - Sun)
l - full name of day (Monday - Sunday)
N - 1=Monday, 2=Tuesday, etc (1-7)
S - suffix for date (st, nd, rd)
w - 0=Sunday, 1=Monday (0-6)
z - day of the year (1=365)

WEEK
W - week of the year (1-52)

MONTH
F - Full name of month (January - December)
m - 2 digit month number (01-12)
n - month number (1-12)
M - 3 letter month (Jan - Dec)
t - Days in the month (28-31)

YEAR
L - leap year (0 no, 1 yes)
o - ISO-8601 year number (Ex. 1979, 2006)

BACK TO TOP

Guide Questions Machine Exercise 1

1. What is your output in Part 1? Describe the output in your discussion.

2. What is your output in Part 2? Describe the output in your discussion.

Answers:

1. The output of the first experiment is more on the configuration of PHP Machine generator. It is composed of different system information on PHP machine, like the system information, Build Date, Server API, Virtual Directory Support, Configuration File (php.ini) Path and configuration of the engine.
List of Directives is also completely stated in a systematic manner of presentation using tabular form. Library support in PhP is also displayed in a tabular form so that user would know all the information that a PhP machine can be supported once the sever process codes from the client. PhP variables and the last thing are the end user licensed agreement of the client to server.

2. The output of the second experiment is a simple phrase "Hello, World", which presented the function of Print in PHP language embedded in HTML form; this is done using the basic codes needed to provide a PHP Script. The basic PhP script is encoded he that is composed of <? PhP and the ?> and all the functions for PhP are all encoded inside this tag. All HTML tags are also enclosed inside the quotations, like the example given which it would display the statement “Hello, World”.

BACK TO TOP


Guide Questions Machine Exercise 2

1. What is your output for print_r.php? Describe it in your discussion.

2. What is your output for variables.php? Construct an observation about PHP variables based from the sample script.

3. What is your output for quotes.php? Create an analysis on how the sample script handles quotes.

Answers:

1.
Because of the given script for the machine exercise 2, procedure number 1 which is the combination of the print_r($GLOBAL); the output for the print_r.php are the different variables in PHP that contains all the variable accessible to the script, including both pre- and user define variable. Print_r is the function that can be used to print the values of the $GLOBALS or the special variables of PHP.

2.

The outputs for the variables.php are the following:

San Marcelino – is for the Variable $street
Manila – is for the variable $city
NCR – is for the variable $province
1000 – is for the variable $zip

Base on the given sample script we observed that, in accordance to the rules of assigning variables regardless of its type we have to use the equal sign (=) that will serve as the assignment operator. It must also have a dollar sign before the variable name. Assigning a variable you will observe that is must always begin with a letter or underscore and not a number. To display the output of the given variable we use the script echo that serve as print script. The echo will be followed by the different variables like for the example $street $city and ect. The <br /> tags is use to set the variable output into the next line.

3.

The outputs for the quotes.php are the following:

$First_name is Juan
$last_name is Dela Cruz

These first two lines executed the declartion variable by the value assigned to it. This informs us that double quotes perform the interchange of values that had been declared in the PhP code. while,

\$first_name is $first_name
\$last_name is $last_name

If you can see difference, the output of the last two lines were different from the first two because it uses single quotations which PhP machine translates these codes literally or as is WYSIWYG.

BACK TO TOP


Guide Questions Machine Exercise 3

1. Refer to feedback.html in Part 1. Enter valid information on the form fields and submit the form. What happened? Discuss.

2. After doing Part 2, open to feedback.html, enter valid information on the form fields and submit the form. What happened? Discuss.

3. Refer to feedback2.html in Part 3. Enter valid information on the form fields and submit the form. What happened? How would you differentiate the output of Part 3 from Part 2?

Answers:

1.
After encoding proper form field data and hitting the submit button nothing happen since the form cannot process information encoded to it. A PhP script must be encoded next so the form can now proceed to processing of data inside the form. The HTML form is composed of 3 radio buttons, a name text field, an email text field, a responce text field, a comment text field and a submit button for processing the data.

2.
After putting valid data on the form and hitting the submit button the PhP script that we have encoded and saved leads to testing, upon testing the HTML form we created earlier now proceeded with a new from after hitting the submit button, the sample output are posted below.

"Thank you SHEM CAMPOS for your comments. "
"You stated that you found this example to be excellet and added: NO COMMENT"

Since we have encoded the form in the POST method, The $_POST variable is an array of variable names and values sent by the HTTP POST method. The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

When the user clicks the "Submit" button, the URL will not contain any form data, and will look something like a simple address on the address bar of the web browser.

3.
After hitting the submit button with the same form as part one of the exercise but there is one difference of the processing, this time the processing of the HTML form uses the GET method on PHP.

The output shown at number two was the same as here but there is one difference in the address bar. When the user clicks the "Submit" button, the URL contain many alphanumeric characters that respond to the form data.

The $_GET variable is an array of variable names and values sent by the HTTP GET method.

The $_GET variable is used to collect values from a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and it has limits on the amount of information to send (max. 100 characters).

BACK TO TOP

Guide Questions Machine Exercise 4

MIDTERM / MACHINE EXERCISE 1

Guide Questions:

1. Open handle.php and append the lines below before the echo part:
$total = number_format($total, 2);
$monthly = number_format($monthly, 2);
Save the script.
View calculator.html in your Web browser. Fill out the form with this information:
Price: 99.00
Quantity: 4
Discount: 25.00
Tax: 5.5
Shipping method: Put a move on it.
Number of payments to make: 24
Submit the information to test the script. Analyze the results.
What is number_format() and what does it do?

2. Refer to handle.php script. Rewrite the calculation of total to minimize multiple lines. Use parentheses to establish precedence.
What will be the new formula for calculating the total?

3. Refer to rand.php script. Modify all variables with value of 99 to 365.
Save and test the script.
What is rand() and what does it do?

Answers:

1. Base on the experiment calculator.html after adding the following script:
$total = number_format($total, 2);
$monthly = number_format($monthly, 2);
You will noticed that decimal points of the total payment and monthly payment lessen into two, base on the given format of the script ($total, 2) and ($monthly, 2).
Therfore the number_forrmat() is a function that formats a number with grouped thousands. It specifies how many decimals. If the parameter is set, the number will be formatted with a dot (.) as decimal point. It can also use to format a number in several ways, including choosing how many decimal points it will have, and choosing the 1000s, and decimal point dividers.

2. The new formula will become:
$total=((($price*$quality)+$shipping)-$discount);

3. Modifying all variable with a value of 99 to 365 the output will display 3 different numbers ranging from 99 to 365. The rand() function is for generating a random number between two given parameters.


BACK TO TOP

Guide Questions Machine Exercise 5

1. Test posting.html and submit the form with this information:
First Name: Joe
Last Name: D’Mango
Email Address: jdmango@address.com
Posting: I’ll greet and say “Hello!”
Take note of the result particularly the posting. What do you notice?

2. Locate the two commented lines for $name and $posting in handle_post.php and undo the comment.
// Adust for magic quotes.
$name = stripslashes($name);
$posting = stripslashes($posting);
Do the same task for $name and $email in thanks.php.
// Adust for magic quotes.
$name = stripslashes($name);
$email = stripslashes($email);
Run and test post.html again using the same information mentioned above.
Explain what happened after modifying the scripts

Answers:
1. The output have an additional characters that binds the posting input, \"Hello!'\ is the output on the posting, which tends to put a backslash on the the comment input. Results where the same over everything that has a Quotation, before the Quotation and after the quotations backslashes where clearly seen in the output.

2. After I undo the comment line in the PhP script, the output on the page leads to stripping off the slashes on the part that the slashes had been generated, this is what the stripslashes function on the PhP does when it sees on the syntax the slashes on the field. The stripslashes() function removes backslashes, This function can be used to clean up data retrieved from a database or from an HTML form.


BACK TO TOP

Guide Questions Machine Exercise 6


MIDTERM / MACHINE EXERCISE 3

Guide Questions:

1. Run list.html again in your Web browser. This time enter valid integer numbers in the text box and submit the information. Examine the output.
Does the sort() support integer type? How about floating-point values?

2. Refer to handle_list.php. Just before displaying the results, remove the echo and foreach loop.
Replace these lines with this code:
$string_words = implode('<br />', $words_array);
echo "<p>An alphabetized version of your list is:<br />$string_words</p>";
View list.html again and test it using the same information mentioned in the procedure.
Explain what happened after modifying the script.

Answers:

1. Yes. The sort() funtion support integer type and also floating-point values. This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.

2. After modifying the script the output display does not change.


BACK TO TOP

 

• Copyright August 2008 JULIUSACAMPOS© • All Rights Reserved •