PHP Set 5 Flashcards
What are superglobal variables?
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
What is the $GLOBALS superglobal variable?
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
What is the $_SERVER superglobal variable?
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
What is the $_REQUEST superglobal variable?
Used to collect data after submitting an HTML form
What is the $_POST superglobal variable?
Used to collect form data after submitting an HTML form with method=”post”
Can be used for connecting to a database
What is the $_GET superglobal variable?
Used to collect form data after submitting an HTML form with method=”get”
Can be used for connecting to a database
What is the $_FILES superglobal variable?
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.
What is a POST method upload?
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.
What is the $_ENV superglobal variable?
Allows you to access environment variables
Ex: $_ENV[“USER”]=”Admin”
echo .$_ENV[“USER”]
What is a cookie?
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 do you create a cookie?
Using the setcookie() function
setcookie(name, value, expire, path, domain, secure, httponly);
Only the name parameter is mandatory, the rest are optional
When is the cookie sent from the browser to the server?
Every time the same computer requests a page, it will send the cookie too so the server can identify the user
How can you delete a cookie?
Use the setcookie() function with an expiration date in the past
What is the $_COOKIE superglobal variable?
Used to access cookies
$_COOKIE[$cookie_name]
What is a session?
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