0
0
PHPprogramming~10 mins

Why superglobals exist in PHP - Test Your Understanding

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

Complete the code to access the value of a GET parameter named 'user'.

PHP
$username = $_[1]['user'];
Drag options to blanks, or click blank then click option'
ACOOKIE
BPOST
CSESSION
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_POST instead of $_GET for URL parameters.
Trying to access $_SESSION without starting a session.
2fill in blank
medium

Complete the code to set a session variable named 'loggedIn' to true.

PHP
session_start();
$_[1]['loggedIn'] = true;
Drag options to blanks, or click blank then click option'
ASESSION
BPOST
CCOOKIE
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to call session_start() before accessing $_SESSION.
Using $_POST or $_GET instead of $_SESSION for session data.
3fill in blank
hard

Fix the error in the code to correctly retrieve a cookie named 'theme'.

PHP
$theme = $_[1]['theme'];
Drag options to blanks, or click blank then click option'
ASESSION
BCOOKIE
CPOST
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_SESSION or $_POST to access cookie data.
Trying to access cookies without checking if they exist.
4fill in blank
hard

Fill both blanks to create an array that holds input data from POST and COOKIE.

PHP
$allData = array_merge($_[1], $_[2]);
Drag options to blanks, or click blank then click option'
AGET
BPOST
CCOOKIE
DSESSION
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_GET instead of $_POST for form data.
Including $_SESSION which is not input data.
5fill in blank
hard

Fill all three blanks to check if a POST parameter 'email' exists and is not empty.

PHP
if (isset($_[1]['email']) && $_[2]['email'] [3] '') {
    echo 'Email received';
}
Drag options to blanks, or click blank then click option'
APOST
C!=
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_GET instead of $_POST for form data.
Using '==' instead of '!=' to check for non-empty value.