Hey Everyone,
Post your solutions to the practice midterm problems to this thread. Remember to list all your teammates.
Best,
Chris
Group 1: Nathanael Garza, Gaoussou Diallo, Ilan Granot, Sebrianne Ferguson
a) DNS is a protocol that resolves an IP address from a domain name. Browser will use this to retrieve the IP address of the webpage. b) TCP is a protocol to set the “frame” for exchanging data between computers over the internet. The browser uses TCP to establish a reliable connection to the webpage c) HTTP is a protocol that is used to transfer data related to the WWW between browsers and web servers. The browser uses HTTP to send GET requests to retrieve the contents of the webpage
(Edited: 2021-03-22)Question 2: Give an example HTTP/1.1 HEAD request message that might be used for the url http://www.cs.sjsu.edu/faculty/pollett/174.1.21s/PracMid1.html. Give an example successful HTTP Response message. <br><br> By Brian Tao, Sunny Xu, Liuyang Zheng <br><br>
'''Example HTTP/1.1 HEAD request message:''' <br> HEAD /faculty/pollett/174.1.21s/PracMid1.html HTTP/1.1<br> Host: cs.sjsu.edu<br> Accept: text/* <br><br> '''Example HTTP response message:''' <br> <u>Minimal response:</u><br> HTTP/1.1 200 OK <br><br> <u>Longer response:</u><br> HTTP/1.1 200 OK<br> Date: Mon, 22 Mar 2021 15:20:45 PST<br> Server: Apache/2.2.2 (Fedora)<br> Accept-Ranges: bytes<br> Connection: close<br> Content-Type: text/html<br>
(Edited: 2021-03-22)Group: James Taylor, Emily Chan, Atul Murali
Problem 8: Explain (a) how HTTP cookies are set and retrieved, (b) how sessions are implemented with cookies, (c) how to use PHP's $_SESSION superglobal and what is happening behind the scenes with regards to cookies and files.
a) HTTP cookies are set using Set-Cookie: name=value; expires=date; path=somepath; domain=somedomain;. Cookies are received in the http response like this: Cookie: seesion_id = jhakda.
b) A session is a collection of information about one user's interaction with a web site. Cookies can be used to implement sessions. A single name-value pair: session_id=some-random-string is sent as a cookie together with an expiration time. This pair when sent from the browser is used to look up on the server a file containing a serialized associative array of user data.
c) To set/get values of the session one uses the global array variable _SESSION. For example, _SESSION["session_name"] gets the session value, and $_SESSION["session_name"] = "value" can set the session value. With regards to what’s happening behind the scenes for cookies/files, the cookie is a small file written to the user’s computer and read by a PHP script when the user sends a request to the server (for identifying them).
Group 7 Sean Chan, Earl Padron, and Sean Quach
<nowiki> <?php if(!isset($_REQUEST["day"])) { ?> <!DOCTYPE html> <html> <head> <title>Days</title> </head>
<body>
<form method="get">
<label for="day">Choose a Date</label>
<select name="day">
<?php
$daysOld = 365 * 21;
for($i = 1; $i <= $daysOld; $i++) {
?>
<option value="<?=$i?>"><?=$i?></option>
<?php
} ?>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html> <?php } else { ?> <!DOCTYPE html> <html> <head>
</head>
<body>
<p>
<?php
$birthday = date('m/d/Y', strtotime('04/28/1999'));
echo date('d/m/Y', strtotime($birthday . ' + ' . $_REQUEST['day'] . ' days'));
?>
</p>
</body>
</html>
<?php
} </nowiki>
(Edited: 2021-03-22)Caitlyn Chau, Hanh Nguyen
Question 9: Briefly explain and give an example use of the following design patterns: (a) mediating Model View Controller, (b) Post Redirect Get.**
Mediating Model View Controller is a variant of MVC. Instead of the controller interacting with the model, and the model updating the views in traditional MVC, the controller invokes BOTH model and view functions. The controller becomes a communication hub accepting any updates from both Model objects and UI events from the View. An example use case is like Assignment 2, where the user clicks on Cause links, which sends form data in the URL. The controller would process that form data and calls the appropriate view to display while also getting any appropriate databases.
Post Redirect Get is another design pattern that lets the page shown after a form submission be reloaded, shared, or bookmarked without resubmitting the form again. An example use case would be in e-commerce websites like Amazon. If a user refreshes the page after placing their order, they would not be charged multiple times.
'''Group 6: Ajay Salh, Masaki Kudo, Tanmay Siwach'''
In copy mode, the PHP processor will copy XHTML to the output and will not make any attempt to interpret what's written. In interpretive mode, PHP code is executed and the result of the code is outputted.
PHP starts in copy mode. To switch to interpretive mode, use "<?php" to denote that code must be executed/interpreted before being output. To switch to copy mode, use "?>" to denote to the PHP processor that from ?> onward, the output will be copied verbatim.
When PHP reads <?php inside a function, it will switch to interpretive mode and attempt to execute the file from that point as a sequence of PHP statements. Reading ?> will switch back to copy mode and will read the copy part of the function as if it were an "echo" statement.
(Edited: 2021-03-22)Question 3: Write a complete XHTML 5 document inviting people to a party in the town where you were born. The document should have a link tag for a style sheet and meta tag that indicates robots should not index the page. It should also make constructive use of an h1 tag and an unordered list.
Group: Christopher Perez, Xochitl Medina, Patricia Caceres
<!DOCTYPE html> <html> <head>
<title>Invite</title>
<link rel="stylesheet" href="style.css">
<meta name="robots" content="noindex">
</head>
<body> <h1>Invitation to my party</h1> <p>It will be in my hometown: Hollister</p>
<p>Are you coming?</p>
<ul>
<li>Yes</li>
<li>No</li>
</ul>
</body> </html>
(Edited: 2021-03-22)Group: Alexa Kegarice, Christopher Louie, Nikki Gowan Question 4. Explain the difference between data tables and layout tables. Give an HTML example of an accessible data table where the data items involve the last four digits of your student ID.
Data tables are used to display tabular data. They can have headers for either the rows, columns, or both for accessibility. Layout tables are used for controlling the layout of the page, but is now discouraged, and CSS should be used instead.
<pre> <!doctype html> <html> <head> <title>midterm practice 4</title> <meta charset="utf-8" />
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head> <body> <h1>practice problem 4</h1> <table> <caption>Table of Numbers</caption> <tr><th scope="col" id='label-column'>Row Name</th><th scope="col" id='number-column'>Number</th></tr> <tr><th scope="row" id='number-two'>number 2</th><td scope="row" id='two-row'>2</td></tr> <tr><th scope="row" id='number-one'>number 0</th><td scope="row" id='zero-row'>0</td></tr> <tr><th scope="row" id='number-two'>number 2</th><td scope="row" id='second-row'>2</td></tr> <tr><th scope="row" id='number-one'>number 1</th><td scope="row" id='one-row'>1</td></tr> </table> </body> </html> </pre>
(Edited: 2021-03-22)Group 5 Ricky, Dat, and Aung
<!DOCTYPE html> <html> <head> <style> span.asl { display:inline-block; background-color: green; }
span.dat {
position: center fixed;
/*position: center;*/
}
p:hover {
visibility: hidden;
}
</style>
</head>
<body>
<h3>I am here to explain how inline block works in css. You can see my name "ASL" in green color. ASL</h3>
<br />
<h3> <span class="asl">I am here to explain how inline block works in css. You can see my name "ASL" in green color. ASL </span></h3>
<br />
<h4><span class="dat"> DAT </span><h4>
<br />
<p><span class="ricky"> RICKY </span></p>
</body>
</html>