Sessions Flashcards

1
Q

filter_input() - How would you use ‘filter_input’ to securely fetch and validate an email address passed as a ‘GET’ parameter?

A

$email = filter_input(INPUT_GET, ‘email’, FILTER_VALIDATE_EMAIL);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you check if a form input named “email” has been submitted and is not null using PHP?

A

if (isset($_POST[‘email’])) {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you access a submitted form value for a field named “password” using the POST method in PHP?

A

$password = $_POST[‘password’];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you retrieve a query parameter named “id” from the URL using PHP?

A

$id = $_GET[‘id’];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you start a session and set a session variable named “user” to store a user’s username in PHP?

A

session_start();
$_SESSION[‘user’] = ‘username’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the below variable likely doing?

$data = get_term($_GET[‘term’]);

A

It is likely being used to store a users search query.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

header(“Location: home.php”);

A

This will redirect to a particular web page. In this example it will redirect to the home page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is this code snippet likely doing:

if (isset($_POST[‘logout’])) {
session_destroy();
header(‘Location: index.php”);

A

The code is likely logging a user out whilst removing all session data associated with it.

It then redirects the user back to the index.php page (usually the homepage)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly