Chapter 7 Flashcards

1
Q

I want to add new columns to my database. What would I use here: _____ _____ mismatch_user ADD username VARCHAR(32) NOT NULL AFTER user_id, ADD password VARCHAR(40) NOT NULL AFTER username;

A

ALTER TABLE ALTER TABLE mismatch_user ADD username VARCHAR(32) NOT NULL AFTER user_id, ADD password VARCHAR(40) NOT NULL AFTER username;

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

What does SHA() stand for?

A

Secure Hash Algorithm

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

What is SHA() used for?

A
  • SHA() is used to encrypt data inserted into a table using the Secure Hash Algorithm
  • SHA() create a 40 character hexadecimal encrypted string using a one way encryption scheme
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

SHA() create a 20 character hexadecimal encrypted string using a two way encryption scheme.

True or False?

A

False:

SHA() creates a 40 character hexadecimal encrypted string using a one way encryption scheme.

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

True or False

SHA() creates a 40 character hexadecimal encrypted string using a one way encryption scheme.

A

True

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

True or False:

mysqli_real_escape_string() is used to protect against SQL injection attacks by escaping special characters in a string used for an SQL statement.

A

True

$user_username = mysqli_real_escape_string($dbc, trim($_SERVER[‘PHP_AUTH_USER’]));

$user_password = mysqli_real_escape_string($dbc, trim($_SERVER[‘PHP_AUTH_PW’]));

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

What does the mysqli_real_escape_string() function do?

A

mysqli_real_escape_string() is used for escaping special characters in a string used for anSQL statement.

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

What does the trim() function do?

A

The trim() function trimms whitespace from either end of the string.

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

What are the components of a cookie?

A
  • Name
  • Value
  • Expiration Date
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A cookie will last forever. True or False?

A

False, a cookie will last as long as it’s set expiration date.

If the expiration date is not set, it will last until the user dismisses the browser session.

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

What do cookies do?

A

Cookies allow the persistance of small pieces of data on the client that have a time limit and can be deleted at will.

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

What does the function setcookie() do?

A

setcookie() allows you to set the name, value, and expiration of a cookie.

setcookie(‘username’, ‘kenmarks’);

setcookie(‘user_id’, ‘1’);

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

$_COOKIE does what?

A

$_COOKIE is a superglobal used to retrieve the value of a cookie.

echo ‘

You are logged in as ‘ . $_COOKIE[‘username’] . ‘.

’;

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

True or False:

Using cookies for log-in means that you can also use the HTTP Authorization header

A

False:

Using Cookies for log-in information means you cannot use the HTTP Authorization header

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

True or False:

Using Cookies for log-in information means you cannot use the HTTP Authorization header

A

True.

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

How do you use cookies to log a user out?

A

setcookie()

Use setcookie() to set back the time which forces the deletion of the Cookie

setcookie(‘username’, ‘kemarks’, time() - 3600);

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

What doe sthe following code do:

setcookie(‘username’, ‘kemarks’, time() - 3600);

A

Sets back the time by one hour to log the user out.

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

What arethe three main positive attributes of Sessions?

A
  • Sessions are not dependent upon the client
  • Sessions store information on the server (not the client).
  • Session information expires when the session ends (i.e. the user closes the browser)
19
Q

How do you start a session in PHP?

A

session_start()

20
Q

How do you end a session in PHP?

A

session_destroy()

21
Q

True or False:

When you end a session, the session variables are all destroyed.

A

False:

The session variables are not destroyed until the browser is closed

22
Q

True or False:

The session variables are not destroyed until the browser is closed

A

True

23
Q

What is $_SESSION?

A

$_SESSION is a superglobal used to retrieve the session variables.

echo ‘

You are logged in as ‘ . $_SESSION[‘username’] . ‘.

’;

24
Q

True or False:

$_SESSION is a superglobal used to retrieve the session variables.

A

True

25
Q

True or False:

$_SESSION is a superglobal used to retrieve the cookie variables.

A

False:

$_SESSION is a superglobal used to retrieve the session variables.

26
Q

True or False

Session variables are automatically deleted when a session is destroyed.

A

False:

Session variables are not automatically deleted when a session is destroyed

27
Q

True or False:

Session variables are not automatically deleted when a session is destroyed

A

True

28
Q

To force the removal of all the session variables for the current session you would do what?

A

$_SESSION = array ();

29
Q

True or False

Sessions are long lived.

A

False:

Sessions are short lived. They only last as long as the current browser session. I fthe user closes the browser tab, the session is destroyed.

30
Q

True or False:

Sessions are short lived. They only last as long as the current browser session. I fthe user closes the browser tab, the session is destroyed.

A

True

31
Q

True or False:

Sessions can not work with cookies.

A

False

Sessions can work with Cookies. If the browser allows Cookies, a session may set a Cookie that temporarily stores the session ID. You access the session ID using the session_name() function.

32
Q

True or False:

in order to fully close a session, you must delete any Cookies that were created to store the session ID.

A

True:

if (isset($_COOKIE[session_name()]))

{

setcookie(session_name(), ‘’, time() - 3600);

}

33
Q

What is setcookie()

A

The built in PHP function is used to set a cookie on the browser, including an optional expiration date, after which the cookie is destroyed. If no expiration is provided, the cookie is deleted when the browser is closed.

34
Q

What is session_start()

A

This built in PHP function starts a new session or re-starts a pre-existing session. You must call this function prior to accessing any session variable.

35
Q

Define:

empty($_COOKIE[‘user_id’])

A

use a cookie to determine if a user is logged in or not.

36
Q

Define:

setcookie(session_name(), ‘’, time() - 3600;

A

Destroy a session cookie by setting its expiration to an hour in the past.

37
Q

Define:

SHA(‘$user_password’)

A

Encrypt a user’s password into an unrecognizable format.

38
Q

Define:

session_destroy()

A

Close the current session.

39
Q

Define:

setcookie(‘user_id’, $row[‘user_id’])

A

Store a user’s unique ID in a cookie

40
Q

Define:

$_SESSION = array()

A

Destroy all session variables

41
Q

session_start()

A

Start a new session

42
Q

isset($_SESSION[‘user_id’])

A

Use a session variable to determine if a user is logged in or not.

43
Q
A