Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which function is used to split a string into a series of substrings, with each string boundary is determined by a specific separator?(a) break()(b) divide()(c) explode()(d) md5()I had been asked this question by my school teacher while I was bunking the class.This question is from User Authentication topic in division File and Session Handling in PHP of PHP

Answer»

The correct ANSWER is (C) explode()

The explanation is: Although they are a SIMILAR function, you should use explode() instead of split(). In fact split() function has been deprecated ALTOGETHER.

52.

Which is the most powerful authentication method among the four?(a) Hard-coding a loginpair directly into the script(b) File-based authentication(c) Data-based authentication(d) PEAR’S HTTP authenticationI got this question in an online interview.This interesting question is from User Authentication topic in chapter File and Session Handling in PHP of PHP

Answer»

The correct choice is (c) Data-based authentication

Easy EXPLANATION: It not only enhances ADMINISTRATIVE convenience and scalability but ALSO can be integrated into a larger DATABASE INFRASTRUCTURE.

53.

The authenticationFile.txt, the file which stores username and password should be stored ___ the server document root.(a) Inside(b) Outside(c) Within(d) None of the mentionedI had been asked this question in a national level competition.Enquiry is from User Authentication in portion File and Session Handling in PHP of PHP

Answer»

The correct option is (B) Outside

Easy explanation: If it is not STORED outside, the attacker could discover the FILE through brute force GUESSING.

54.

In which authentication method does changing the username or password can be done only by entering the code and making the manual adjustment.(a) Hard-coding a loginpair directly into the script(b) File-based authentication(c) Data-based authentication(d) PEAR’S HTTP authenticationThe question was posed to me during an interview.The query is from User Authentication topic in division File and Session Handling in PHP of PHP

Answer»

The CORRECT CHOICE is (a) Hard-coding a loginpair directly into the script

To elaborate: The SIMPLEST way to restrict resource access is by hard-coding the username and password directly into the script. In this authentication method, changing the username or password can be done only by entering the code and making the manual adjustment. This is one of the DRAWBACKS of hard-coding a login PAIR directly into the script.

55.

Which function is used to verify whether a variable contains a value?(a) header()(b) footer()(c) inset()(d) isset()I have been asked this question by my college professor while I was bunking the class.Question is from User Authentication in section File and Session Handling in PHP of PHP

Answer»

Right answer is (d) isset()

EASY explanation: The isset() function determines WHETHER a variable has been ASSIGNED a value. Its prototype follows: BOOLEAN isset(mixed VAR [,mixed var [,…]]).

56.

How many predefined variables does PHP use to authenticate a user?(a) 1(b) 2(c) 3(d) 4The question was posed to me at a job interview.My question is taken from User Authentication topic in division File and Session Handling in PHP of PHP

Answer»

Correct answer is (B) 2

The explanation is: The variables PHP USE to authenticate a user are $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’].

57.

How many validation filters like FILTER_VALIDATE_EMAIL are currently available?(a) 5(b) 6(c) 7(d) 8The question was asked in an internship interview.I would like to ask this question from HTML Forms topic in section File and Session Handling in PHP of PHP

Answer»

The CORRECT answer is (C) 7

To explain I WOULD SAY: There are seven validation filters. They are FILTER_VALIDATE_EMAIL, FILTER_VALIDATE_BOOLEAN, FILTER_VALIDATE_FLOAT, FILTER_VALIDATE_INT, FILTER_VALIDATE_IP, FILTER_VALIDATE_REGEXP, FILTER_VALIDATE_URL.

58.

To validate an email address, which flag is to be passed to the function filter_var()?(a) FILTER_VALIDATE_EMAIL(b) FILTER_VALIDATE_MAIL(c) VALIDATE_EMAIL(d) VALIDATE_MAILThis question was posed to me in an online interview.This question is from HTML Forms topic in section File and Session Handling in PHP of PHP

Answer» CORRECT OPTION is (a) FILTER_VALIDATE_EMAIL

Explanation: The FILTER_VALIDATE_EMAIL is USED to VALIDATES an e-mail ADDRESS.
59.

Which function is used to remove all HTML tags from a string passed to a form?(a) remove_tags()(b) strip_tags()(c) tags_strip()(d) tags_remove()I have been asked this question in a job interview.Question is taken from HTML Forms topic in division File and Session Handling in PHP of PHP

Answer»

Right option is (b) strip_tags()

For EXPLANATION: The function strip_tags() is used to strip a STRING from HTML, XML, and PHP tags.

60.

Which one of the following should not be used while sending passwords or other sensitive information?(a) GET(b) POST(c) REQUEST(d) NEXTThe question was asked in exam.The question is from HTML Forms topic in section File and Session Handling in PHP of PHP

Answer»

The correct choice is (a) GET

To explain I WOULD say: 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.

61.

Which variable is used to collect form data sent with both the GET and POST methods?(a) $BOTH(b) $_BOTH(c) $REQUEST(d) $_REQUESTThe question was posed to me in final exam.The above asked question is from HTML Forms topic in chapter File and Session Handling in PHP of PHP

Answer» CORRECT CHOICE is (d) $_REQUEST

Easy explanation: In PHP the global variable $_REQUEST is used to collect DATA after submitting an HTML FORM.
62.

When you use the $_POST variable to collect data, the data is visible to ___________(a) none(b) only you(c) everyone(d) selected fewI got this question in unit test.I need to ask this question from HTML Forms in portion File and Session Handling in PHP of PHP

Answer»

Right choice is (b) only you

Best 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.

63.

When you use the $_GET variable to collect data, the data is visible to ___________(a) none(b) only you(c) everyone(d) selected fewThis question was posed to me during an interview.My doubt is from HTML Forms in division File and Session Handling in PHP of PHP

Answer»

The CORRECT OPTION is (c) everyone

The best I can explain: 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.

64.

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) scriptingThe question was posed to me in homework.I want to ask this question from HTML Forms in portion File and Session Handling in PHP of PHP

Answer»

Correct choice is (c) cross-site scripting

Easy 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.

65.

Which two predefined variables are used to retrieve information from forms?(a) $GET & $SET(b) $_GET & $_SET(c) $__GET & $__SET(d) GET & SETThis question was posed to me in an interview for internship.My doubt is from HTML Forms in portion File and Session Handling in PHP of PHP

Answer»

Right answer is (b) $_GET & $_SET

Easiest 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.

66.

Which method enables you to calculate whether daylight saving time is in force at a specific date and time?(a) getOffset()(b) getTranitions()(c) ISODate()(d) savingTime()I had been asked this question in examination.This intriguing question originated from Working with Dates in portion File and Session Handling in PHP of PHP

Answer»

Right ANSWER is (b) getTranitions()

BEST explanation: This outputs a multidimensional array listing PAST and future changes to the offset from UTC for a DateTimeZone OBJECT.

67.

Which of the following statements can be used to add two months to the existing date?(a) $date->modify(‘+2 months’);(b) $date = modify(‘+2 months’);(c) $date = modify(‘2+ months’);(d) $date->modify(‘2+ months’);I have been asked this question in a national level competition.Query is from Working with Dates in division File and Session Handling in PHP of PHP

Answer»

Right choice is (a) $date->MODIFY(‘+2 months’);

The explanation is: To change the date stored by a DATETIME object after it has been created, you USE DateTime::modify() with a natural language EXPRESSION.

68.

Which of the following statements can be used to set the time zone in individual scripts?(a) date_set_timezone(‘Europe/London’);(b) date_default_timezone_set(‘Europe/London’);(c) date_set_default_timezone(‘Europe/London’);(d) date_default_timezone(‘Europe/London’);I had been asked this question during an interview for a job.My query is from Working with Dates in section File and Session Handling in PHP of PHP

Answer»

The correct answer is (b) date_default_timezone_set(‘Europe/London’);

Explanation: The FUNCTION date_default_timezone_setis used to set the default time ZONE used by all date/time functions in a script. You can also USE ini_set(‘date.timezone’, ‘Europe/London’);

69.

Which of the following is the right way to use the DateTime class?(a) $date = get_Class(DateTime);(b) $date = class DateTime;(c) $date = new DateTime();(d) $date = new class DateTime();The question was posed to me by my school principal while I was bunking the class.Query is from Working with Dates topic in chapter File and Session Handling in PHP of PHP

Answer»

Correct choice is (c) $date = new DateTime();

The explanation is: The way you use the DateTime class is like any other class: instantiate an OBJECT, and STORE it in a VARIABLE.

70.

Which method is simply an object-oriented version of date()?(a) DateTime::format()(b) DateTime::modify()(c) DateTime::setTime()(d) DateTime::setDate()The question was posed to me during an online exam.I want to ask this question from Working with Dates topic in division File and Session Handling in PHP of PHP

Answer»

Correct option is (a) DateTime::FORMAT()

To explain: The format() method is SIMPLY an object-oriented version of DATE(). It takes $dateFormat as an argument. $dateFormat is a string consisting of the same date formatting characters accepted by the PROCEDURAL date() function.

71.

How many constants does the DateTime class have?(a) 8(b) 9(c) 10(d) 11I had been asked this question in an online quiz.This is a very interesting question from Working with Dates topic in chapter File and Session Handling in PHP of PHP

Answer»

The correct ANSWER is (d) 11

The explanation: The DateTime CLASS has 11 constants, no static properties or METHODS.

72.

How many methods does the DateTime class have?(a) 8(b) 9(c) 10(d) 11This question was addressed to me in final exam.Enquiry is from Working with Dates in division File and Session Handling in PHP of PHP

Answer»

The correct answer is (B) 9

Explanation: The DATETIME CLASS has NINE methods, all of which are PUBLIC.

73.

To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?(a) $date = Date(“22 JUNE 2013”)(b) $date = new Date(“JUNE 22 2013”)(c) $date = DateTime(“22 JUNE 2013”)(d) $date = new DateTime(“22 JUNE 2013”)I have been asked this question during an interview for a job.Asked question is from Date and Timestamp topic in chapter File and Session Handling in PHP of PHP

Answer»

Correct OPTION is (d) $date = NEW DateTime(“22 JUNE 2013”)

To elaborate: The dateTime() method is class constructor. You can set the date EITHER at the time of INSTANTIATION or later by using a variety of mutators.

74.

Suppose you want to calculate the date 45 days from the present date which one of the following statement will you use?(a) totime(“+45”)(b) totime(“+45 days”)(c) strtotime(“+45 days”)(d) strtotime(“-45 days”)This question was addressed to me in quiz.This intriguing question comes from Date and Timestamp in section File and Session Handling in PHP of PHP

Answer»

Correct answer is (C) strtotime(“+45 days”)

Explanation: The strtotime() function and GNU date SYNTAX is USED to calculating the date X days from the present date.

75.

Which function displays the web page’s most recent modification date?(a) lastmod()(b) getlastmod()(c) last_mod()(d) get_last_mod()The question was asked by my school principal while I was bunking the class.Question is from Date and Timestamp in division File and Session Handling in PHP of PHP

Answer» CORRECT choice is (b) getlastmod()

To elaborate: 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.
76.

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()The question was posed to me by my school principal while I was bunking the class.Query is from Date and Timestamp topic in portion File and Session Handling in PHP of PHP

Answer»

The correct choice is (b) mktime()

Easiest 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.

77.

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 zerosI had been asked this question during a job interview.Origin of the question is Date and Timestamp topic in portion File and Session Handling in PHP of PHP

Answer»

The correct answer is (a) Complete text representation of MONTH

Best 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.

78.

Which one of the following format parameter can be used to identify timezone?(a) T(b) N(c) E(d) IThis question was posed to me during an interview.My question is based upon Date and Timestamp in division File and Session Handling in PHP of PHP

Answer»

The CORRECT choice is (c) E

The 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.

79.

The date() function returns ___ representation of the current date and/or time.(a) Integer(b) String(c) Boolean(d) FloatThis question was posed to me during an interview for a job.The above asked question is from Date and Timestamp in portion File and Session Handling in PHP of PHP

Answer»

The correct ANSWER is (b) String

To ELABORATE: The function date() is used to format a local date and time, and it will return the formatted date string. The SYNTAX of this function is string date(string format [, INT timestamp]).

80.

Which one of the following function reads a directory into an Array?(a) scandir()(b) readdir()(c) scandirectory()(d) readdirectory()I have been asked this question in final exam.The doubt is from File System and PHP topic in division File and Session Handling in PHP of PHP

Answer»

The correct option is (a) scandir()

For explanation: It returns an array CONSISTING of files and directories FOUND in DIRECTORY or returns FALSE on ERROR.

81.

Which function is useful when you want to output the executed command result?(a) out_cmm()(b) out_system()(c) cmm()(d) system()This question was posed to me by my school principal while I was bunking the class.My query is from File System and PHP in division File and Session Handling in PHP of PHP

Answer»

The CORRECT choice is (d) system()

Explanation: The function system() in PHP is same as the C version of the function as in that it executes the GIVEN command and outputs the result. This function also tries to automatically FLUSH the web server’s OUTPUT buffer after each line of output if PHP is running as a server module.

82.

Which function sets the file filename last-modified and last-accessed times?(a) sets()(b) set()(c) touch()(d) touched()The question was asked in exam.Origin of the question is File System and PHP in division File and Session Handling in PHP of PHP

Answer»

Correct choice is (C) touch()

The best EXPLANATION: The function touch() will set the access and MODIFICATION time of the specified FILE. Syntax is touch(FILENAME, time, atime).

83.

Which one of the following function operates similarly to fgets(), except that it also strips any HTML and PHP tags form the input?(a) fgetsh()(b) fgetsp()(c) fgetsa()(d) fgetss()The question was asked in semester exam.Question is taken from File System and PHP in section File and Session Handling in PHP of PHP

Answer»

The correct ANSWER is (d) fgetss()

The best I can EXPLAIN: The function fgetss() returns a line, with HTML and PHP TAGS removed, from an open file. This function OPERATES similarly to fgets(), except that it also strips any HTML and PHP tags FORM the input.

84.

Which one of the following function is capable of reading a specific number of characters from a file?(a) fgets()(b) fget()(c) fileget()(d) filegets()The question was asked in a national level competition.The origin of the question is File System and PHP in portion File and Session Handling in PHP of PHP

Answer»

Correct choice is (a) FGETS()

EASY explanation: The function fgets() will return a line from an open file. This stops returning on a NEW line, at the specified length, or at EOF, whichever comes first.Its prototype is string fgets(resource handle [, int length]). If the optional length PARAMETER is omitted, 1024 character is assumed.

85.

Which one of the following function outputs the contents of a string variable to the specified resource?(a) filewrite()(b) fwrite()(c) filewrites()(d) fwrites()This question was posed to me in an interview.This is a very interesting question from File System and PHP in section File and Session Handling in PHP of PHP

Answer»

Right option is (b) fwrite()

EXPLANATION: The function fwrite() writes to an OPEN FILE. This will stop at the end of the file or when it reaches the specified length, whichever comes first.

86.

Which one of the following function is capable of reading a file into an array?(a) file()(b) arrfile()(c) arr_file()(d) file_arr()This question was posed to me during an online interview.I would like to ask this question from File System and PHP in section File and Session Handling in PHP of PHP

Answer»

The CORRECT ANSWER is (a) FILE()

Explanation: The function file() will READ the entire file into an ARRAY.

87.

Which one of the following function is capable of reading a file into a string variable?(a) file_contents()(b) file_get_contents()(c) file_content()(d) file_get_content()This question was addressed to me during an internship interview.Asked question is from File System and PHP in section File and Session Handling in PHP of PHP

Answer»

The correct choice is (b) file_get_contents()

To explain I would say: The function file_get_contents() reads a file into a string. This is the PREFERRED way to read the contents of a file into a string as it will use memory MAPPING TECHNIQUES.

88.

Which one of the following PHP function is used to determine a file’s last access time?(a) fileltime()(b) filectime()(c) fileatime()(d) filetime()I have been asked this question during an online interview.I'm obligated to ask this question of File System and PHP topic in division File and Session Handling in PHP of PHP

Answer»

The correct answer is (C) fileatime()

For explanation: The fileatime() function returns a file’s last ACCESS time in UNIX timestamp format or FALSE on ERROR.

89.

The filesize() function returns the file size in ___________(a) bits(b) bytes(c) kilobytes(d) gigabytesI have been asked this question in an interview.Enquiry is from File System and PHP topic in portion File and Session Handling in PHP of PHP

Answer»

The CORRECT option is (b) bytes

Explanation: The function filesize() returns the size of the specified FILE and it returns the file size in bytes on SUCCESS or FALSE on FAILURE.