Part 4 - Server side Handling data with PHP Flashcards
An array that contains keys and values sent to the server on the end of the URL or by submitting a HTML form using the GET method.
describe the superglobal variable
$_GET
Basic syntax (arguments omitted):
define(name,value)
@param name (Required) Specifies the name of the constant
@param value (Required) Specifies the value of the constant.
describe the syntax and parameters of
define()
what are the syntax and parameters of
var_export()
Syntax:
var_export(variable,return);
@param variable (Required). Specifies the variable to check
@param return (Optional). If set to true, it returns the variable representation instead
of outputting it
describe the function
var_export()
a function that outputs or returns structured information about a variable.
describe the superglobal variable
$_GET
An array that contains keys and values sent to the server on the end of the URL or by submitting a HTML form using the GET method.
describe the function
define()
this function is used to define a constant
describe the syntax and parameters of
empty()
Syntax:
empty(variable);
@param variable (Required) Specifies the variable to check
function used for case insensitive comparison of two strings, returns 0 if the two strings match
describe the function
strcasecmp()
give 3 points that describe
Java
points on this include:
1.Open source
2.Object oriented
3.When used to serve dynamic web content a special web server is required such as Tomcat
describe the function
htmlspecialchars()
a function that converts some predefined characters to HTML entities.
describe the function
strcasecmp()
function used for case insensitive comparison of two strings, returns 0 if the two strings match
describe the
difference between declaring strings with single vs double quotes
Single quotes - these are interpreted exactly as written and so the text within the single quotes will always be unchanged
Double quotes - anything written within double quotes will be interpreted by PHP, this means if a variable name is included it will be evaluated and replaced by its value. Any other escape sequences will also be interpreted within double quotes
To implement this:
1.We set a flag in PHP files that will be requested by URL, the flag states that it is safe for files to run
a)This can be achieved setting a constant using define() function
2.Files that should only be executed via require or include will look for the flag, if it is not set then they will refuse to execute
a)This can be achieved by:
b)Checking if flag is set using the defined() function
c)If the flag is not set we terminate the script using the die() method
This ensures that users can only execute the scripts that we intend them to execute,
describe the implementation that would mitigate users executing the scripts that we will call using the require
and include
statements
this can be mitigated by cleaning text of any characters that could hold code before it is sent to the users browser.
we can accomplish this by using the function htmlspecialchars(). which replaces HTML characters with HTML entities
give one example of how a
Cross site scripting (XSS) attack can be mitigated
in PHP
when we access an array we should always check to see if it is empty.
the reason being because if we access an element that is not there then PHP will output a notice in the HTML. this should be hidden
when accessing an array what action should we perform first and why
these include:
1.Hypertext Preprocessor (PHP)
2.Active Server Pages.NET (ASP.NET)
3.Java
4.Python
5.Node.js
name 5
server side programming languages
Example:
$array = [];
if (!empty($array[‘id’])) {
Code if value exists;
} else {
Code if value does not exist;
}
give an example that checks if an array has content using an if…else statement
give an example that checks if an array has content using an if…else statement
Example:
$array = [];
if (!empty($array[‘id’])) {
Code if value exists;
} else {
Code if value does not exist;
}
using a for each loop write the syntax for extracting the key and value of the current element
syntax:
foreach ($array as $key => $value) { Code to execute; }
points on this include:
1.Open source
2.Object oriented
3.When used to serve dynamic web content a special web server is required such as Tomcat
give 3 points that describe
Java
sometimes known as a dictionary is an array with named keys and associated values for each key
describe an
Associative arrays
An array that contains data previously stored on the server in the current session
describe the superglobal variable
$_SESSION
how do we
declare a constant in PHP
this is accomplished by using the define() function
An array that contains keys and values sent to the server by submitting a HTML form using the POST method.
describe the superglobal variable
$_POST
this is an array that contains data about the server running the PHP script.
describe the superglobal variable
$_SERVER
we acieve this by using:
<?php code ?>
how is PHP code placed inside a PHP document
describe the syntax and parameters of
htmlspecialchars()
Basic syntax (arguments ommitted)
htmlspecialchars(string)
@param string the string to convert
describe the implementation that would mitigate users executing the scripts that we will call using the require
and include
statements
To implement this:
1.We set a flag in PHP files that will be requested by URL, the flag states that it is safe for files to run
a)This can be achieved setting a constant using define() function
2.Files that should only be executed via require or include will look for the flag, if it is not set then they will refuse to execute
a)This can be achieved by:
b)Checking if flag is set using the defined() function
c)If the flag is not set we terminate the script using the die() method
This ensures that users can only execute the scripts that we intend them to execute,
describe the function
basename()
this function returns the filename from a path.
describe the 5
values that are considered
falsey
these include:
1.integer 0 and float 0.0
2.the empty string “” and “0” (because it is equivalent to integer 0)
3.an empty array []
4.the null value
5.and of course, the boolean false
Syntax:
strcasecmp(string1,string2)
@param string1 (Required) Specifies the first string to compare
@param string2 (Required) Specifies the second string to compare
describe the syntax and parameters of
strcasecmp()
this function checks whether a variable/array is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true.
describe the function
empty()
how can we
remove an item from an array
this can be accomplished by using the unset() function
points on this include:
1.Used by youtube and dropbox
2.Usefull for processing large data sets and scientific and statistical data
3.SQLLite is a database that is included with python
give 3 points that describe
python
give one example of how a
Cross site scripting (XSS) attack can be mitigated
in PHP
this can be mitigated by cleaning text of any characters that could hold code before it is sent to the users browser.
we can accomplish this by using the function htmlspecialchars(). which replaces HTML characters with HTML entities
describe the superglobal variable
$_POST
An array that contains keys and values sent to the server by submitting a HTML form using the POST method.
what is the syntax of the PHP while loop
Syntax:
while (condition is true) { code to be executed; }
describe the syntax and parameters of
unset()
Syntax:
unset(variable, ….);
@param variable (Required). Specifies the variable or array value to unset
@param … (Optional) Another variable to unset
this function prints a message and terminates the current script.
describe the function
Die()
describe the 2 types of arrays that can be created
these include:
1.Lists - where an index number is automatically associated with a value
2.Dictianories (Associative array) - where we specify a key and a value for the element in the array
NOTE:
* each key of a dictionary must be unique
* The key of a dictionary can be an integer or string
write out the syntax for an
if…elseif…else block
Syntax:
if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if first condition is false and this condition is true; } else { code to be executed if all conditions are false; }
points on this include:
1.Provides a javascript runtime on the server
2.Efficient at handling large number of requests (scales better than PHP)
3.Allows both client and server side to be written in javascript
give 3 points that describe
node.js
behaviour:
1.Include
- will include the code if the file can be found, but omit it otherwise and continue
2.Require
- if the script being inserted is missing, PHP will stop execution and report an error.
describe the difference in behaviour of the statements
1. include
2. require
describe the function
phpinfo()
this function will output configuration information about PHP such as the version in use
give 3 points that describe
python
points on this include:
1.Used by youtube and dropbox
2.Usefull for processing large data sets and scientific and statistical data
3.SQLLite is a database that is included with python
describe the two methods for
creating an array
these include:
1.Using the array() function
2.Using the [] notation
these include:
- A constant’s value cannot be changed after it is set
- Constant names do not need a leading dollar sign ($)
- Constants can be accessed regardless of scope
- Constant values can only be strings and numbers
what are the
4 rules governing the declaration of constant
describe the superglobal variable
$_SERVER
this is an array that contains data about the server running the PHP script.
these include:
1.A variable name always begins with a dollar character ($) followed by a letter or underscore (never a number)
2.Allowed characters in a variable name are (a-b, 1-9, _)
3.Characters are case sensitive
4.PHP is dynamically typed so we do not need to declare the data type the variable will hold
what are the
4 rules that govern the declaration of variables
variations of this are:
1.extract only the value of the current element
2.Extract the key and value of the current element
describe the 2 variations of the PHP for each loop
describe the function
Die()
this function prints a message and terminates the current script.
how is PHP code placed inside a PHP document
we acieve this by using:
<?php code ?>
Basic Syntax (arguments ommitted):
basename(path)
@param path (Required) Specifies a file path
describe the syntax and paramers of
basename()
Syntax:
while (condition is true) { code to be executed; }
what is the syntax of the PHP while loop