Part 4 - Server side Handling data with PHP Flashcards

1
Q

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.

A

describe the superglobal variable
$_GET

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

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.

A

describe the syntax and parameters of

define()

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

what are the syntax and parameters of

var_export()

A

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

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

describe the function

var_export()

A

a function that outputs or returns structured information about a variable.

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

describe the superglobal variable
$_GET

A

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.

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

describe the function

define()

A

this function is used to define a constant

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

describe the syntax and parameters of

empty()

A

Syntax:
empty(variable);

@param variable (Required) Specifies the variable to check

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

function used for case insensitive comparison of two strings, returns 0 if the two strings match

A

describe the function

strcasecmp()

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

give 3 points that describe
Java

A

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

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

describe the function

htmlspecialchars()

A

a function that converts some predefined characters to HTML entities.

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

describe the function

strcasecmp()

A

function used for case insensitive comparison of two strings, returns 0 if the two strings match

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

describe the
difference between declaring strings with single vs double quotes

A

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

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

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,

A

describe the implementation that would mitigate users executing the scripts that we will call using the require and include statements

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

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

A

give one example of how a
Cross site scripting (XSS) attack can be mitigated
in PHP

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

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

A

when accessing an array what action should we perform first and why

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

these include:
1.Hypertext Preprocessor (PHP)
2.Active Server Pages.NET (ASP.NET)
3.Java
4.Python
5.Node.js

A

name 5
server side programming languages

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

Example:
$array = [];
if (!empty($array[‘id’])) {
Code if value exists;
} else {
Code if value does not exist;
}

A

give an example that checks if an array has content using an if…else statement

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

give an example that checks if an array has content using an if…else statement

A

Example:
$array = [];
if (!empty($array[‘id’])) {
Code if value exists;
} else {
Code if value does not exist;
}

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

using a for each loop write the syntax for extracting the key and value of the current element

A

syntax:

foreach ($array as $key => $value) {
Code to execute;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

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

A

give 3 points that describe
Java

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

sometimes known as a dictionary is an array with named keys and associated values for each key

A

describe an
Associative arrays

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

An array that contains data previously stored on the server in the current session

A

describe the superglobal variable
$_SESSION

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

how do we
declare a constant in PHP

A

this is accomplished by using the define() function

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

An array that contains keys and values sent to the server by submitting a HTML form using the POST method.

A

describe the superglobal variable
$_POST

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

this is an array that contains data about the server running the PHP script.

A

describe the superglobal variable
$_SERVER

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

we acieve this by using:

<?php
code
?>
A

how is PHP code placed inside a PHP document

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

describe the syntax and parameters of

htmlspecialchars()

A

Basic syntax (arguments ommitted)
htmlspecialchars(string)

@param string the string to convert

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

describe the implementation that would mitigate users executing the scripts that we will call using the require and include statements

A

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,

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

describe the function

basename()

A

this function returns the filename from a path.

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

describe the 5
values that are considered
falsey

A

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

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

Syntax:
strcasecmp(string1,string2)

@param string1 (Required) Specifies the first string to compare
@param string2 (Required) Specifies the second string to compare

A

describe the syntax and parameters of

strcasecmp()

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

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.

A

describe the function

empty()

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

how can we
remove an item from an array

A

this can be accomplished by using the unset() function

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

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

A

give 3 points that describe
python

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

give one example of how a
Cross site scripting (XSS) attack can be mitigated
in PHP

A

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

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

describe the superglobal variable
$_POST

A

An array that contains keys and values sent to the server by submitting a HTML form using the POST method.

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

what is the syntax of the PHP while loop

A

Syntax:

while (condition is true) {
code to be executed;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

describe the syntax and parameters of

unset()

A

Syntax:
unset(variable, ….);

@param variable (Required). Specifies the variable or array value to unset
@param … (Optional) Another variable to unset

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

this function prints a message and terminates the current script.

A

describe the function

Die()

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

describe the 2 types of arrays that can be created

A

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

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

write out the syntax for an
if…elseif…else block

A

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;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

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

A

give 3 points that describe
node.js

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

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.

A

describe the difference in behaviour of the statements
1. include
2. require

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

describe the function

phpinfo()

A

this function will output configuration information about PHP such as the version in use

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

give 3 points that describe
python

A

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

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

describe the two methods for
creating an array

A

these include:
1.Using the array() function
2.Using the [] notation

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

these include:

  1. A constant’s value cannot be changed after it is set
  2. Constant names do not need a leading dollar sign ($)
  3. Constants can be accessed regardless of scope
  4. Constant values can only be strings and numbers
A

what are the
4 rules governing the declaration of constant

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

describe the superglobal variable
$_SERVER

A

this is an array that contains data about the server running the PHP script.

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

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

A

what are the
4 rules that govern the declaration of variables

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

variations of this are:
1.extract only the value of the current element
2.Extract the key and value of the current element

A

describe the 2 variations of the PHP for each loop

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

describe the function

Die()

A

this function prints a message and terminates the current script.

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

how is PHP code placed inside a PHP document

A

we acieve this by using:

<?php
code
?>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

Basic Syntax (arguments ommitted):
basename(path)

@param path (Required) Specifies a file path

A

describe the syntax and paramers of

basename()

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

Syntax:

while (condition is true) {
code to be executed;
}
A

what is the syntax of the PHP while loop

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

name 5
server side programming languages

A

these include:
1.Hypertext Preprocessor (PHP)
2.Active Server Pages.NET (ASP.NET)
3.Java
4.Python
5.Node.js

56
Q

what are the 3 methods for commenting in PHP

A

these include:

// This is a basic one-line PHP comment
/* This is a C-style PHP comment that can span multiple lines.
Note it must be closed */
# This is a “shell-style” PHP one-line comment.

NOTE: Most likely the first two comment styles are most likely to be encountered

57
Q

describe the superglobal variable
$_FILES

A

An array that contains data about files uploaded using a special type of POST request.

58
Q

what are the
4 rules governing the declaration of constant

A

these include:

  1. A constant’s value cannot be changed after it is set
  2. Constant names do not need a leading dollar sign ($)
  3. Constants can be accessed regardless of scope
  4. Constant values can only be strings and numbers
59
Q

what is the
syntax for extracting data from an array

A

Syntax:

$arrayName[index/key]

60
Q

within a double quoted string what are the 3 ways to include a variable

A

this can be achieved using any of the following:
1. $var
2. ${var}
3. {$var}

NOTE: for readability it might be preferrable to use method 3

61
Q

describe the superglobal variable
$_SESSION

A

An array that contains data previously stored on the server in the current session

62
Q

the data is sent within a HTTP request and then made available to PHP via its superglobal variables

A

how is the HTML form data made available to a PHP script upon submition

63
Q

Syntax:
empty(variable);

@param variable (Required) Specifies the variable to check

A

describe the syntax and parameters of

empty()

64
Q

using a for each loop write the syntax for
extracting only the value of the current element

A

syntax:

foreach ($array as $value) {
    code to be executed;
}
65
Q

this function is used to define a constant

A

describe the function

define()

66
Q

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

A

describe the 5
values that are considered
falsey

67
Q

syntax:

foreach ($array as $value) {
    code to be executed;
}
A

using a for each loop write the syntax for
extracting only the value of the current element

68
Q

Basic syntax (arguments ommitted)
htmlspecialchars(string)

@param string the string to convert

A

describe the syntax and parameters of

htmlspecialchars()

69
Q

this pattern of processing may be:
1.Generate a welcome page with a choice of tasks and send this to the user.
2.Receive back a request with data on the task to carry out. Generate a new page to respond to that request using data from the database. The full page itself never exists on the server. Only a collection of templates and data in the servers.
3.Repeat this second series of actions.

A

describe the pattern of processing that PHP might take when in a session with a user but the session is not user specific

70
Q

define
Cross site scripting (XSS)

A

this is an attack that allows a user to inject there own scripts into a website. when the website is loaded there is potential that this script could be ran on an unsuspecting users browser

71
Q

describe a typical use case for
Hypertext Preprocessor (PHP)

A

This is typically used where all or part of a web page must be dynamically created.

The data it uses to create the page will most likely be retrieved from one or more databases

72
Q

a function that converts some predefined characters to HTML entities.

A

describe the function

htmlspecialchars()

73
Q

when creating a condition in a while loop what type of tests are recommended

A

When programming loops it can be better to test a condition such as (<=, >=, <, >) rather than equality (==)

74
Q

This is typically used where all or part of a web page must be dynamically created.

The data it uses to create the page will most likely be retrieved from one or more databases

A

describe a typical use case for
Hypertext Preprocessor (PHP)

75
Q

these include:

// This is a basic one-line PHP comment
/* This is a C-style PHP comment that can span multiple lines.
Note it must be closed */
# This is a “shell-style” PHP one-line comment.

NOTE: Most likely the first two comment styles are most likely to be encountered

A

what are the 3 methods for commenting in PHP

76
Q

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

A

what are the syntax and parameters of

var_export()

77
Q

give 3 points about
superglobal variables

A

points include:
1.These are built in variables of PHP
2.They can be accessed from any scope
3.Each of these is an array, so can be iterated over using a for each loop or looking for a specific item using its key

78
Q

Syntax:
Die(message)

@param message (Required) A message or status number to print before terminating the script. A status number will not be written to the output, just used as the exit status.

A

describe the syntax and paramers of

die()

79
Q

describe the superglobal variable
$_COOKIE

A

An array that contains cookies sent to the server that were previously set by the same server.

80
Q

describe an
Associative arrays

A

sometimes known as a dictionary is an array with named keys and associated values for each key

81
Q

what are the
4 rules that govern the declaration of variables

A

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

82
Q

Syntax:
unset(variable, ….);

@param variable (Required). Specifies the variable or array value to unset
@param … (Optional) Another variable to unset

A

describe the syntax and parameters of

unset()

83
Q

these include:
1. $_SERVER
2. $_GET
3. $_POST
4. $_FILES
5. $_COOKIE
6. $_SESSION

A

name 6
important superglobal variables

84
Q

this is accomplished by using the define() function

A

how do we
declare a constant in PHP

85
Q

when accessing an array what action should we perform first and why

A

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

86
Q

these include
1.Loose comparison (==) - will only check that two values are the same
2.Strict comparison (===) - will check that both the type and value are the same

A

describe the 2
methods of comparison

87
Q

the reason for this is because it is possible for a user to send any data to the server

A

why should incoming data to a server always be cleaned on the server

88
Q

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

A

describe the
difference between declaring strings with single vs double quotes

89
Q

describe the 2 variations of the PHP for each loop

A

variations of this are:
1.extract only the value of the current element
2.Extract the key and value of the current element

90
Q

this function returns the filename from a path.

A

describe the function

basename()

91
Q

describe the function

empty()

A

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.

92
Q

describe the pattern of processing that PHP might take when in a session with a specific user

A

this pattern of processing might be:
1. Generate a welcome page with forms for the user to sign in.
2. Receive the sign in, validate the data, and authenticate the user.
3. Receive data back from the user, validate the data. Identify the user from the session
4. continue step 3 untill user signs out or there is inactivity

NOTE: at steps 2 and 3 we may have further processing including accessing a database and creating unique pages for the user

93
Q

how do we perform a
not operation

A

this is achieved using the exclamation mark (!)

94
Q

why should incoming data to a server always be cleaned on the server

A

the reason for this is because it is possible for a user to send any data to the server

95
Q

how is the HTML form data made available to a PHP script upon submition

A

the data is sent within a HTTP request and then made available to PHP via its superglobal variables

96
Q

this can be achieved using any of the following:
1. $var
2. ${var}
3. {$var}

NOTE: for readability it might be preferrable to use method 3

A

within a double quoted string what are the 3 ways to include a variable

97
Q

these include:
1.Using the array() function
2.Using the [] notation

A

describe the two methods for
creating an array

98
Q

how can we dynamically include a seperate PHP file into our current PHP file

A

this can be accomplished using the statements
1. include
2. require

99
Q

Syntax:

$arrayName[index/key] = newValue;

A

what is the syntax for
updating a value in an array

100
Q

When programming loops it can be better to test a condition such as (<=, >=, <, >) rather than equality (==)

A

when creating a condition in a while loop what type of tests are recommended

101
Q

this pattern of processing might be:
1. Generate a welcome page with forms for the user to sign in.
2. Receive the sign in, validate the data, and authenticate the user.
3. Receive data back from the user, validate the data. Identify the user from the session
4. continue step 3 untill user signs out or there is inactivity

NOTE: at steps 2 and 3 we may have further processing including accessing a database and creating unique pages for the user

A

describe the pattern of processing that PHP might take when in a session with a specific user

102
Q

Syntax:

$arrayName[index/key]

A

what is the
syntax for extracting data from an array

103
Q

describe the syntax and paramers of

basename()

A

Basic Syntax (arguments ommitted):
basename(path)

@param path (Required) Specifies a file path

104
Q

describe the 2
methods of comparison

A

these include
1.Loose comparison (==) - will only check that two values are the same
2.Strict comparison (===) - will check that both the type and value are the same

105
Q

when implementing the server side of a web application name 5 items that would be required

A

for this we require:
1.infrastructure - Dedicated hardware or cloud infrastructure
2.operating system - that can interact with the hardware and run software on top of
3.Web server software - that can handle incoming and outgoing messages to the internet and interact with other server software
4.server side programming language - to handle buisness logic and data processing
5.Database software and associated hardware - so that data can be stored and retrieved

106
Q

a function that outputs or returns structured information about a variable.

A

describe the function

var_export()

107
Q

function used to unset/destroy variable and array values

A

describe the function

unset()

108
Q

describe the syntax and paramers of

die()

A

Syntax:
Die(message)

@param message (Required) A message or status number to print before terminating the script. A status number will not be written to the output, just used as the exit status.

109
Q

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

A

describe the 2 types of arrays that can be created

110
Q

how is string concatenation performed

A

this is achieved using dot notation

example:

<?php
$mystring1 = 'The Cat';
$mystring2 = 'on the mat';
$mystring3 = 'got the cream';
$mystring4 = $mystring1 . ' ' . $mystring3;
echo "<p>$mystring4</p>";
//Output: <p>The Cat got the cream</p>
?>
111
Q

this can be accomplished by using the unset() function

A

how can we
remove an item from an array

112
Q

describe the difference in behaviour of the statements
1. include
2. require

A

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.

113
Q

the risk of having these is that a user could potentially find there URL and execute them.

NOTE: these scripts could potentially give data away that we did not intend

A

what is the risk of having seperate PHP files that we will use via include and require

114
Q

points include:
1.These are built in variables of PHP
2.They can be accessed from any scope
3.Each of these is an array, so can be iterated over using a for each loop or looking for a specific item using its key

A

give 3 points about
superglobal variables

115
Q

describe the function

unset()

A

function used to unset/destroy variable and array values

116
Q

what is the risk of having seperate PHP files that we will use via include and require

A

the risk of having these is that a user could potentially find there URL and execute them.

NOTE: these scripts could potentially give data away that we did not intend

117
Q

give 3 points that describe
node.js

A

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

118
Q

this is an attack that allows a user to inject there own scripts into a website. when the website is loaded there is potential that this script could be ran on an unsuspecting users browser

A

define
Cross site scripting (XSS)

119
Q

in 4 steps describe a Cross site scripting (XSS) that
1. injects code via the comments
2. creates an alert when visitors view the website

A

Example:
1.A script tag with an alert is placed inside a comments section
2.The comment gets saved as is in the database
3.When new visitors view the comments the script tag will be pulled from the database and dynamically inserted into the html and sent to the user
4.The users browser sees the script tag in the HTML and runs the alert

NOTE: within the script tags could be any kind of malicious code

120
Q

this can be accomplished using the statements
1. include
2. require

A

how can we dynamically include a seperate PHP file into our current PHP file

121
Q

for this we require:
1.infrastructure - Dedicated hardware or cloud infrastructure
2.operating system - that can interact with the hardware and run software on top of
3.Web server software - that can handle incoming and outgoing messages to the internet and interact with other server software
4.server side programming language - to handle buisness logic and data processing
5.Database software and associated hardware - so that data can be stored and retrieved

A

when implementing the server side of a web application name 5 items that would be required

122
Q

describe the pattern of processing that PHP might take when in a session with a user but the session is not user specific

A

this pattern of processing may be:
1.Generate a welcome page with a choice of tasks and send this to the user.
2.Receive back a request with data on the task to carry out. Generate a new page to respond to that request using data from the database. The full page itself never exists on the server. Only a collection of templates and data in the servers.
3.Repeat this second series of actions.

123
Q

this is achieved using dot notation

example:

<?php
$mystring1 = 'The Cat';
$mystring2 = 'on the mat';
$mystring3 = 'got the cream';
$mystring4 = $mystring1 . ' ' . $mystring3;
echo "<p>$mystring4</p>";
//Output: <p>The Cat got the cream</p>
?>
A

how is string concatenation performed

124
Q

points on this include:
1.Open source and freely available
2.General purpose
3.but especially suited to web development because PHP can be easily embedded within HTML and can also dynamically create HTML
4.Commonly installed on apache server running linux
5.Can be installed on linux, windows and macOS

A

give 5 points that describe
Hypertext Preprocessor (PHP)

125
Q

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;
}
A

write out the syntax for an
if…elseif…else block

126
Q

what is the syntax for
updating a value in an array

A

Syntax:

$arrayName[index/key] = newValue;

127
Q

An array that contains data about files uploaded using a special type of POST request.

A

describe the superglobal variable
$_FILES

128
Q

give 5 points that describe
Hypertext Preprocessor (PHP)

A

points on this include:
1.Open source and freely available
2.General purpose
3.but especially suited to web development because PHP can be easily embedded within HTML and can also dynamically create HTML
4.Commonly installed on apache server running linux
5.Can be installed on linux, windows and macOS

129
Q

An array that contains cookies sent to the server that were previously set by the same server.

A

describe the superglobal variable
$_COOKIE

130
Q

this function will output configuration information about PHP such as the version in use

A

describe the function

phpinfo()

131
Q

this is achieved using the exclamation mark (!)

A

how do we perform a
not operation

132
Q

syntax:

foreach ($array as $key => $value) {
Code to execute;
}
A

using a for each loop write the syntax for extracting the key and value of the current element

133
Q

name 6
important superglobal variables

A

these include:
1. $_SERVER
2. $_GET
3. $_POST
4. $_FILES
5. $_COOKIE
6. $_SESSION

134
Q

describe the syntax and parameters of

define()

A

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.

135
Q

Example:
1.A script tag with an alert is placed inside a comments section
2.The comment gets saved as is in the database
3.When new visitors view the comments the script tag will be pulled from the database and dynamically inserted into the html and sent to the user
4.The users browser sees the script tag in the HTML and runs the alert

NOTE: within the script tags could be any kind of malicious code

A

in 4 steps describe a Cross site scripting (XSS) that
1. injects code via the comments
2. creates an alert when visitors view the website

136
Q

describe the syntax and parameters of

strcasecmp()

A

Syntax:
strcasecmp(string1,string2)

@param string1 (Required) Specifies the first string to compare
@param string2 (Required) Specifies the second string to compare