PHP Questions and Answers Part-19

1. Which one of the following format parameter can be used to identify timezone?
a) T
b) N
c) E
d) I

Answer: c
Explanation: When the format is E the time zone is identified and returned, for example, America/New York. N denotes ISO-8601 numeric representation of the day of the week, T denotes time zone abbreviation, I denotes whether or not the date is in daylight saving time.

2. If the format is F then which one of the following will be returned?
a) Complete text representation of month
b) Day of month, with leading zero
c) Daylight saving time
d) Day of month, without zeros

Answer: a
Explanation: F represents a full textual representation of a month, such as January or March. Day of month, with leading zero is represented by D, Daylight saving time by I, Day of month without zeros by j.

3. Which one of the following function is useful for producing a timestamp based on a given date and time?
a) time()
b) mktime()
c) mrtime()
d) mtime()

Answer: b
Explanation: The function mktime() returns the Unix timestamp for a date. This function is same as gmmktime() except that the passed parameters represents a date not a GMT date.

4. Which function displays the web page’s most recent modification date?
a) lastmod()
b) getlastmod()
c) last_mod()
d) get_last_mod()

Answer: b
Explanation: The function getlastmod() gets the time of the last modification of the main script of execution. It returns the value of the page’s last modified header or FALSE in the case of an error.

5. Which two predefined variables are used to retrieve information from forms?
a) $GET & $SET
b) $_GET & $_SET
c) $__GET & $__SET
d) GET & SET

Answer: b
Explanation: The global variables $_GET is used to collect form data after submitting an HTML form with the method=”get”. The variable $_SET is also used to retrieve information from forms.

6. The attack which involves the insertion of malicious code into a page frequented by other users is known as _______________
a) basic sql injection
b) advanced sql injection
c) cross-site scripting
d) scripting

Answer: c
Explanation: The cross-site scripting attack is among one of the top five security attacks carried out across the Internet. It is also known as XSS, this attack is a type of code injection attack which is made possible by incorrectly validating user data, which usually gets inserted into the page through a web form or using an altered hyperlink.

7. When you use the $_GET variable to collect data, the data is visible to ___________
a) none
b) only you
c) everyone
d) selected few

Answer: c
Explanation: The information sent from a form with the method GET is visible to everyone i.e. all variable names and values are displayed in the URL.

8. When you use the $_POST variable to collect data, the data is visible to ___________
a) none
b) only you
c) everyone
d) selected few

Answer: b
Explanation: The information sent from a form with the method POST is invisible to others i.e. all names/values are embedded within the body of the HTTP request.

9. Which variable is used to collect form data sent with both the GET and POST methods?
a) $BOTH
b) $_BOTH
c) $REQUEST
d) $_REQUEST

Answer: d
Explanation: In PHP the global variable $_REQUEST is used to collect data after submitting an HTML form.

10. Which one of the following should not be used while sending passwords or other sensitive information?
a) GET
b) POST
c) REQUEST
d) NEXT

Answer: a
Explanation: The information sent from a form with the method GET is visible to everyone i.e. all variable names and values are displayed in the URL. So, it should not be used while sending passwords or other sensitive information.