0
0
PHPprogramming~10 mins

PHP process model per request - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a PHP script that outputs a simple message.

PHP
<?php
 echo [1];
?>
Drag options to blanks, or click blank then click option'
Aecho "Hello, world!"
B'Hello, world!'
CHello, world!
D"Hello, world!"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string.
Trying to echo without quotes.
2fill in blank
medium

Complete the code to define a variable holding the current request method.

PHP
<?php
 $method = [1]['REQUEST_METHOD'];
?>
Drag options to blanks, or click blank then click option'
A$_POST
B$_SERVER
C$_GET
D$_REQUEST
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_GET or $_POST which hold user input, not server info.
Using $_REQUEST which combines GET, POST, and COOKIE.
3fill in blank
hard

Fix the error in the code that tries to start a session per request.

PHP
<?php
 [1]();
 // session code here
?>
Drag options to blanks, or click blank then click option'
Asession_start
Bstart_session
Cbegin_session
DsessionBegin
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like start_session().
Forgetting the underscore in the function name.
4fill in blank
hard

Fill both blanks to create an associative array with request method and URI.

PHP
<?php
 $request = [
   'method' => [1],
   'uri' => [2]
 ];
?>
Drag options to blanks, or click blank then click option'
A$_SERVER['REQUEST_METHOD']
B$_SERVER['REQUEST_URI']
C$_GET['REQUEST_METHOD']
D$_GET['REQUEST_URI']
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_GET instead of $_SERVER for these values.
Mixing REQUEST_METHOD and REQUEST_URI incorrectly.
5fill in blank
hard

Fill all three blanks to create a response array with status, headers, and body.

PHP
<?php
 $response = [
   'status' => [1],
   'headers' => [2],
   'body' => [3]
 ];
?>
Drag options to blanks, or click blank then click option'
A200
B['Content-Type' => 'text/html']
C"<h1>Hello</h1>"
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using status as a string instead of a number.
Not using an array for headers.
Forgetting quotes around the body string.