Midterm Study 3 Flashcards
Is HTTP a stateful or or stateless protocol?
HTTP is a stateless protocol, meaning there is no built-in mechanism for linking one HTTP request with another.
What is session management?
Any web app that remembers who the user is and/or what they were doing from one HTTP request to the next is using some form of session management
What gets sent to the client along with the HTTP response in order to implement session management?
A cookie (token) usually valid until the browser is closed.
How is the cookie used?
The cookie contains a unique id to identify the user. When the user initiates a new HTTP request, the browser sends the cookie back along with it. When the server receives a request with a session cookie, it can look up the id to retrieve information about the session
How do you start a session and where does it go?
session_start();
Starts or resumes a session. Must be called before any output has been written into the HTTP Response (i.e. above the line in a PHP web page).
How is session information stored?
$_SESSION[]
An associative array to store and retrieve data for the current session. You can store values of any type in this array, including other Array values. Values that come from user-defined parameters should be validated and/or filtered before they are stored
How do you remove all values from a session?
session_unset()
Removes all values from $_SESSION.
How do you end a session?
session_destroy();
Terminates the session. The next call to session_start() will start a new session with an empty $_SESSION[]object. Note that you must call session_start() to resume the session before you can destroy it.
What is the number one way websites and databases get hacked in the real world?
SQL Injections
What does PDO stand for?
PHP Data Objects
What is a SQL injection?
An injection attack is a malicious hack that can occur any time user input is executed as code
What is the number 1 way to prevent SQL injections?
Prepared statements
What does the syntax for a prepared statement look like?
$id = filter_input(INPUT_POST, “id”, FILTER_SANITIZE_SPECIAL_CHARS); $command=”DELETE FROM polls WHERE ID=?”;
$stmt = $dbh->prepare($command);
$userParams = [$deleteid];
$stmt->execute($userParams);
What does a SELECT statement look like in SQL
SELECT * FROM “mytable” WHERE “quantity” = 0
What does an INSERT statement look like in SQL?
INSERT INTO “mytable” (col1, col2) VALUES (22, ‘String’)