PHP Set 5 Flashcards

1
Q

What are superglobal variables?

A

Built-in variables that are always available in all scopes so you can access them from any function, class, or file without needing to do anything special

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

What is the $GLOBALS superglobal variable?

A

A variable that is used to access global variables from anywhere in the PHP script.
All globals are stored in $GLOBALS[index] where index is the name of the variable

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

What is the $_SERVER superglobal variable?

A

Contains information about headers, paths, and script locations
1. $_SERVER[‘SERVER_ADDR’] Returns the IP address of the host server
2. $_SERVER[‘SERVER_NAME’] Returns the URL of the host server
3. $_SERVER[‘REQUEST_METHOD’] Returns the request method used to access
the page.
4. $_SERVER[‘REMOTE_ADDR’] Returns the IP address from where the user is
viewing the current page
5. $_SERVER[‘SERVER_PORT’] Returns the port on the server machine

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

What is the $_REQUEST superglobal variable?

A

Used to collect data after submitting an HTML form

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

What is the $_POST superglobal variable?

A

Used to collect form data after submitting an HTML form with method=”post”
Can be used for connecting to a database

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

What is the $_GET superglobal variable?

A

Used to collect form data after submitting an HTML form with method=”get”
Can be used for connecting to a database

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

What is the $_FILES superglobal variable?

A

Contains all file information that has been uploaded to the current script via the HTTP POST method
Ex:
1. $_FILES[‘userfile’][‘name’]; The original name of the file on the client machine.
2. $_FILES[‘userfile’][‘size’]; The size, in bytes, of the uploaded file.
3. $_FILES[‘userfile’][‘error’]; The error code associated with this file upload.

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

What is a POST method upload?

A

Lets people upload text and binary files. Uses PHP’s authentication and file manipulation functions so you have full control over who is allowed to upload and what is to be done with the file once it is uploaded.

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

What is the $_ENV superglobal variable?

A

Allows you to access environment variables
Ex: $_ENV[“USER”]=”Admin”
echo .$_ENV[“USER”]

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

What is a cookie?

A

A piece of data from a web server that is stored within a web browser for the web server to recognize a web user

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

How do you create a cookie?

A

Using the setcookie() function
setcookie(name, value, expire, path, domain, secure, httponly);
Only the name parameter is mandatory, the rest are optional

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

When is the cookie sent from the browser to the server?

A

Every time the same computer requests a page, it will send the cookie too so the server can identify the user

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

How can you delete a cookie?

A

Use the setcookie() function with an expiration date in the past

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

What is the $_COOKIE superglobal variable?

A

Used to access cookies
$_COOKIE[$cookie_name]

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

What is a session?

A

A global variable stored on the server. Each session is assigned a unique ID which is used to retrieve stored values.
When a session is created, a cookie containing the session ID is stored on the user’s computer and is returned with every request to the server.
Session values are automatically deleted when the browser is closed

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

What is the difference between a session and a cookie?

A

Sessions can store relatively large data compared to cookies

17
Q

When should you use a session?

A
  1. When you want to pass values from one page to another
  2. When you want to store important information more securely on the server
  3. When you want an alternative to cookies for browsers that do not support cookies
  4. When you want to store global variables in a more efficient and secure way compared to passing them in a URL
  5. When you’re developing an application that needs to store temporary information larger than 4KB
18
Q

How do you start a session?

A

Using the session_start() method

19
Q

What is the _$SESSION superglobal variable?

A

An associative array that contains session variables available to the current script

20
Q

How do you delete a session?

A

Using the session_destroy() and unset() functions
Ex: session_destroy();
unset($_SESSION[“data”]);