2022-10-10

Practice Midterm Problem Thread.

Please post the solution for your problem to the practice midterm to this thread.
Best,
Chris
Please post the solution for your problem to the practice midterm to this thread. Best, Chris

-- Practice Midterm Problem Thread
Mark Masulis, Luke Brouwer, Nicholas Hui
 6. 
 a. Cookies are set and returned using HTTP headers.
 The server uses the "Set-Cookie" header followed by name-value pairs to set cookies.
 To send the cookies back to the server, the client uses the "Cookie" header followed by name-value pairs.
 b. A server can implement sessions by setting a cookie with a string which can be used 
 to look up a file. The file contains session data for that client.
 c. To set a session in PHP, use
 session_start();
 to begin the session. This has to happen before any HTML is output. Then if you want to use a session id other than PHPSESSID, use
 session_name($session_id);
 Then, you can access session variables through the array
 $_SESSION["name"]
(Edited: 2022-10-10)
Mark Masulis, Luke Brouwer, Nicholas Hui 6. a. Cookies are set and returned using HTTP headers. The server uses the "Set-Cookie" header followed by name-value pairs to set cookies. To send the cookies back to the server, the client uses the "Cookie" header followed by name-value pairs. b. A server can implement sessions by setting a cookie with a string which can be used to look up a file. The file contains session data for that client. c. To set a session in PHP, use session_start(); to begin the session. This has to happen before any HTML is output. Then if you want to use a session id other than PHPSESSID, use session_name($session_id); Then, you can access session variables through the array $_SESSION["name"]

-- Practice Midterm Problem Thread
1. Give example HTTP/1.1 request and response Request: GET /home.html HTTP/1.1 Host: interior.gov Accept: text/* Accept: image/gif Response: HTTP/1.1 418 I'm a teapot 2. Give a notable difference between HTTP/1.1 and HTTP 2.0. The difference between HTTP 1.1 and 2.0 is that HTTP 2.0+ requires encryption. HTTP 2.0 is also sent in a binary succint format whereas HTTP 1.1 uses plain text. 3. Give a notable difference between HTTP/2.0 and HTTP 3.0. The difference between HTTP/2.0 and 3.0 is that 3.0 uses the QUIC protocol for connection rather than TCP like HTTP 2.0 does. Members: Aaron Li Brandon Ong Andre Domingo Aadit Dubey
(Edited: 2022-10-10)
<nowiki> 1. Give example HTTP/1.1 request and response Request: GET /home.html HTTP/1.1 Host: interior.gov Accept: text/* Accept: image/gif Response: HTTP/1.1 418 I'm a teapot 2. Give a notable difference between HTTP/1.1 and HTTP 2.0. The difference between HTTP 1.1 and 2.0 is that HTTP 2.0+ requires encryption. HTTP 2.0 is also sent in a binary succint format whereas HTTP 1.1 uses plain text. 3. Give a notable difference between HTTP/2.0 and HTTP 3.0. The difference between HTTP/2.0 and 3.0 is that 3.0 uses the QUIC protocol for connection rather than TCP like HTTP 2.0 does. Members: Aaron Li Brandon Ong Andre Domingo Aadit Dubey </nowiki>

-- Practice Midterm Problem Thread
Nick Tang, Jeffrey Yang, Seungmi Na
Q2. <!DOCTYPE html> <html> <head>
    <link rel=”stylesheet” herf=”stylesheet.css”>
    <mteta name="robots" content="NOINDEX" />
    <title> Midterm 1</title>
</head>
    <body>
        <h1> Midterm 1</h1>
        <ol>
            <li>questoin1</li>
            <li>questoin2</li>
            <li>questoin3</li>
        </ol>
    </body>
</html>
(Edited: 2022-10-10)
Nick Tang, Jeffrey Yang, Seungmi Na Q2. <!DOCTYPE html> <html> <head> <link rel=”stylesheet” herf=”stylesheet.css”> <mteta name="robots" content="NOINDEX" /> <title> Midterm 1</title> </head> <body> <h1> Midterm 1</h1> <ol> <li>questoin1</li> <li>questoin2</li> <li>questoin3</li> </ol> </body> </html>

-- Practice Midterm Problem Thread
Ross Nikolai Montepalco, Cary Lefteroff, Michael Ruiz Question 4: https://imgur.com/7J7Kf4J
(Edited: 2022-10-10)
Ross Nikolai Montepalco, Cary Lefteroff, Michael Ruiz Question 4: https://imgur.com/7J7Kf4J

-- Practice Midterm Problem Thread
Max Wong, Neeharika Kandikattu, Jaime Zuspann
Question 10: Write a PHP program with function drawStuffTable which makes a connection to a Mysql database StuffDB running on localhost on the default port. It then retrieves all rows and columns from the Stuff table and prints then to an XHTML page.
<?php function drawStuffTable() {
    $db = mysqli_connect();
    mysqli_select_db($db, “StuffDB”);
    $query = “SELECT * FROM  StuffDB”;
    $result = mysqli_query($db, $query);
    $num_rows = mysqli_num_rows($result);
    for ($i = 0; $i < $num_rows; $i++) {
        $row = mysqli_fetch_array($result);
         print_r($row);
    }
}
(Edited: 2022-10-10)
Max Wong, Neeharika Kandikattu, Jaime Zuspann Question 10: Write a PHP program with function drawStuffTable which makes a connection to a Mysql database StuffDB running on localhost on the default port. It then retrieves all rows and columns from the Stuff table and prints then to an XHTML page. <?php function drawStuffTable() { $db = mysqli_connect(); mysqli_select_db($db, “StuffDB”); $query = “SELECT * FROM StuffDB”; $result = mysqli_query($db, $query); $num_rows = mysqli_num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $row = mysqli_fetch_array($result); print_r($row); } }

-- Practice Midterm Problem Thread
Tiffany Phan & Sabrina Ly Number 3:
(a) CSS Class Selector A css class selector selects elements with a specific class attribute. It is typically used with a period, followed by the class name Example: CSS: .box-background-color {background-color: blue} HTML: <div class=background> Test </div>
(b) CSS Pseudo-selector, This is a CSS pseudo-selector in which CSS styling is applied when an event occurs. An example of an event is when a mouse hovers over a tag. To start a pseudo-selector is select an element tag followed by a colon then the event name. CSS: P:hover {color:blue;} HTML: <p> Test </p>
(C) fixed positioning. An element that takes a fixed positioning CSS value of position property stays in the same place even when the scroll bar is scrolled. An element with a position that is fixed. CSS: P.example { position: relative;} HTML: <p class = ‘example’> Example </p>
(Edited: 2022-10-10)
Tiffany Phan & Sabrina Ly Number 3: (a) CSS Class Selector A css class selector selects elements with a specific class attribute. It is typically used with a period, followed by the class name Example: CSS: .box-background-color {background-color: blue} HTML: <div class=background> Test </div> (b) CSS Pseudo-selector, This is a CSS pseudo-selector in which CSS styling is applied when an event occurs. An example of an event is when a mouse hovers over a tag. To start a pseudo-selector is select an element tag followed by a colon then the event name. CSS: P:hover {color:blue;} HTML: <p> Test </p> (C) fixed positioning. An element that takes a fixed positioning CSS value of position property stays in the same place even when the scroll bar is scrolled. An element with a position that is fixed. CSS: P.example { position: relative;} HTML: <p class = ‘example’> Example </p>

-- Practice Midterm Problem Thread
Group Members: Alan Ngo, Siddhita Joshi, Tyler Nguyen Question 8: Briefly describe the POST-REDIRECT-GET Pattern When a form is submitted using the POST method, the data is sent in the request body. If the user refreshes or clicks the back button, the data would be submitted again if the user clicks the confirmation button. To fix this, we can use the POST-REDIRECT-GET pattern to redirect using a 301 redirect and a location header. The user will be sent to a safe page using a GET request. This allows the user to bookmark the page, refresh, or use the back button without resubmitting the data.
(Edited: 2022-10-10)
Group Members: Alan Ngo, Siddhita Joshi, Tyler Nguyen Question 8: Briefly describe the POST-REDIRECT-GET Pattern When a form is submitted using the POST method, the data is sent in the request body. If the user refreshes or clicks the back button, the data would be submitted again if the user clicks the confirmation button. To fix this, we can use the POST-REDIRECT-GET pattern to redirect using a 301 redirect and a location header. The user will be sent to a safe page using a GET request. This allows the user to bookmark the page, refresh, or use the back button without resubmitting the data.

-- Practice Midterm Problem Thread
Fernando Gonzalez, Howell DeGuzman, Dustin Nguyen Q5: <!DOCTYPE html> <html> <body> <form method="GET"> <select name="select">
    <?php for ($x = 1; $x <= 100000; $x++) { ?>
    <option name="num"><?php echo $x; ?></option>
    <?php } ?>
<input type="submit" value="Submit"/> </select> </form> </body> <?php if (isset($_GET['select'])) {
    $t = time() - 60 * 60 * $_GET['select'];
    echo date('Y-m-d H:i', $t);
} else {
    echo '';
} ?> </html>
(Edited: 2022-10-10)
Fernando Gonzalez, Howell DeGuzman, Dustin Nguyen Q5: <!DOCTYPE html> <html> <body> <form method="GET"> <select name="select"> <?php for ($x = 1; $x <= 100000; $x++) { ?> <option name="num"><?php echo $x; ?></option> <?php } ?> <input type="submit" value="Submit"/> </select> </form> </body> <?php if (isset($_GET['select'])) { $t = time() - 60 * 60 * $_GET['select']; echo date('Y-m-d H:i', $t); } else { echo ''; } ?> </html>

-- Practice Midterm Problem Thread
MVC is a software architecture pattern that separates the code into three parts: the model, view, and controller. The model is the data logic. The view is a graphical representation of the current model. The controller is the intermediary between the view and the controller.
<?php
// Model ( session variable ) session_start(); if (!isset($_SESSION['counter'])) {
    $_SESSION['counter'] = 0;
}
// View function view($counter) {
    ?><!DOCTYPE html>
    <html>
        <head>
            <title>MVC</title>
        </head>
        <body>
        <?php
            echo '<form method="post" action="index.php">';
            echo '<input type="hidden" name="counter" value="' . $counter . '">';
            echo '<input type="submit" name="click" value="Click Me">';
            echo '</form>';
            echo '<p>Counter: ' . $counter . '</p>';
        ?>
        </body>
    </html><?php
}
// Controller function controller() {
    if (isset($_POST['click'])) {
        $_SESSION['counter']++;
    }
    view($_SESSION['counter']);
}
controller();
?>
MVC is a software architecture pattern that separates the code into three parts: the model, view, and controller. The model is the data logic. The view is a graphical representation of the current model. The controller is the intermediary between the view and the controller. <?php // Model ( session variable ) session_start(); if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 0; } // View function view($counter) { ?><!DOCTYPE html> <html> <head> <title>MVC</title> </head> <body> <?php echo '<form method="post" action="index.php">'; echo '<input type="hidden" name="counter" value="' . $counter . '">'; echo '<input type="submit" name="click" value="Click Me">'; echo '</form>'; echo '<p>Counter: ' . $counter . '</p>'; ?> </body> </html><?php } // Controller function controller() { if (isset($_POST['click'])) { $_SESSION['counter']++; } view($_SESSION['counter']); } controller(); ?>
X