Sessions Flashcards
filter_input() - How would you use ‘filter_input’ to securely fetch and validate an email address passed as a ‘GET’ parameter?
$email = filter_input(INPUT_GET, ‘email’, FILTER_VALIDATE_EMAIL);
How do you check if a form input named “email” has been submitted and is not null using PHP?
if (isset($_POST[‘email’])) {}
How do you access a submitted form value for a field named “password” using the POST method in PHP?
$password = $_POST[‘password’];
How do you retrieve a query parameter named “id” from the URL using PHP?
$id = $_GET[‘id’];
How do you start a session and set a session variable named “user” to store a user’s username in PHP?
session_start();
$_SESSION[‘user’] = ‘username’;
What is the below variable likely doing?
$data = get_term($_GET[‘term’]);
It is likely being used to store a users search query.
header(“Location: home.php”);
This will redirect to a particular web page. In this example it will redirect to the home page
What is this code snippet likely doing:
if (isset($_POST[‘logout’])) {
session_destroy();
header(‘Location: index.php”);
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)