Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

PHP MCQ Set 1

1. Which function is used to erase all session variables stored in the current session?
a) session_destroy()
b) session_change()
c) session_remove()
d) session_unset()

View Answer

Answer: d [Reason:] This will not completely remove the session from the storage mechanism. If you want to completely destroy the session, you need to use the function session_destroy().

2. What will the function session_id() return is no parameter is passed?
a) Current Session Identification Number
b) Previous Session Identification Number
c) Last Session Identification Number
d) Error

View Answer

Answer: a [Reason:] None.

3. Which one of the following statements should you use to set the session username to Nachi?
a) $SESSION[‘username’] = “Nachi”;
b) $_SESSION[‘username’] = “Nachi”;
c) session_start(“nachi”);
d) $SESSION_START[“username”] = “Nachi”;

View Answer

Answer: b [Reason:] You need to refer the session variable ‘username’ in the context of the $_SESSION superglobal.

4. What will be the output of the following PHP code? Say your previous session username was nachi.

  1.     unset($_SESSION['username']);
  2.     printf("Username now set to: %s", $_SESSION['username']);

a) Username now set to: nachi
b) Username now set to: System
c) Username now set to:
d) Error

View Answer

Answer: c [Reason:] To delete the session variable ‘username’ we use the unset() function.

5. An attacker somehow obtains an unsuspecting user’s SID and then using it to impersonate the user inorder to gain potentially sensitive information. This attack is known as..
a) session-fixation
b) session-fixing
c) session-hijack
d) session-copy

View Answer

Answer: a [Reason:] You can minimize this risk by regenerating the session ID on each request while maintaining the session-specified data. PHP offers a convenient function named session_regenerate_id() that will replace the existing ID with a new one.

6. Which parameter determines whether the old session file will also be deleted when the session ID is regenerated?
a) delete_old_file
b) delete_old_session
c) delete_old_session_file
d) delete_session_file

View Answer

Answer: b [Reason:] By default, this behavior is disabled.

7. Which function effectively deletes all sessions that have expired?
a) session_delete()
b) session_destroy()
c) session_garbage_collect()
d) session_expired_delete()

View Answer

Answer: c [Reason:] None.

8. Which function is used to transform PHP’s session-handler behavior into that defined by your custom handler?
a) session_set_save()
b) session_set_save_handler()
c) Session_handler()
d) session_save_handler()

View Answer

Answer: b [Reason:] None.

9. The session_start() function must appear..
a) after the html tag
b) after the body tag
c) before the body tag
d) before the html tag

View Answer

Answer: d [Reason:] Like this: <?php session_start(); ?> <html>

10. What is the return type of session_set_save_handler() function?
a) boolean
b) integer
c) float
d) character

View Answer

Answer: a [Reason:] Returns TRUE on success or FALSE on failure.

PHP MCQ Set 2

1. When you are building administrative links you’ll need to accept two arguments, which of the following are they?
a) URL of previous entry and URL of the entry you are working with
b) The current page and previous page
c) URL of previous entry and previous page
d) The current page and URL of the entry you are working with

View Answer

Answer: d [Reason:] Your function should look like this:

  1. function adminLinks($page, $url)
  2. {
  3.   //Build admin links here
  4. }

2. Once your application can generate administrative links, you need to load those links into _________
a) php.ini
b) index.ini
c) index.php
d) start.php
View Ansewr

Answer: c [Reason:] You place your administrative links only on the full display of an entry, so you must place the call to load information from adminLinks() within a conditional statement

3. The URLs in the administrative links won’t mean anything to admin.php unless you modify _________
a) .htaccess
b) .adminaccess
c) .htmlaccess
d) .urlaccess

View Answer

Answer: a [Reason:] You need to modify .htaccess with an additional rule that handles URLs passed in a link to admin.php.

4. The (|/) tells the server to match ___________
a) nothing
b) forward slash
c) backward slash
d) either nothing or a forward slash

View Answer

Answer: d [Reason:] The vertical pipe character (|) is the regular expression equivalent of “or”.

5. ([w-]+) will match ___________
a) one word characters
b) one or more word characters
c) one or more word characters and/or hypens
d) one or more word characters and hypens

View Answer

Answer: c [Reason:] ([w-]+), will match one or more word characters and/or hyphens—which is what your custom entry URLs consist.

6. You need to check whether ______ is set, to determine whether you’re editing an entry or creating a new one.
a) $_GET[‘url’].
b) $_SET[‘url’].
c) $_GET[‘admin’].
d) $_SET[‘admin’].

View Answer

Answer: a [Reason:] If an entry is being edited, you need to load the existing entry data and save each piece in a variable.

7. To identify entries marked for deletion, you check whether $_GET[‘page’] == ‘delete’ inside __________
a) index.php
b) index.ini
c) admin.php
d) .htaccess

View Answer

Answer: c [Reason:] In admin.php, you check whether $_GET[‘page’] == ‘delete’, then pass the entry URL to be deleted to a function.

8. To declare the function to confirm the deletion you need to add the code to __________
a) inc.php
b) functions.inc.php
c) include.php
d) functions.include.php

View Answer

Answer: b [Reason:] You need to add the following code –

  1. function confirmDelete($db, $url)
  2. {
  3.     $e = retrieveEntries($db, '', $url);
  4.     return <<<FORM
  5.     <form action="/simple_blog/admin.php" method="post">
  6.     <fieldset>
  7.     <legend>Are You Sure?</legend>
  8.     <p>Are you sure you want to delete the entry "$e[title]"?</p>
  9.     <input type="submit" name="submit" value="Yes" />
  10.     <input type="submit" name="submit" value="No" />
  11.     <input type="hidden" name="action" value="delete" />
  12.     <input type="hidden" name="url" value="$url" />
  13.     </fieldset>
  14.     </form>
  15.     FORM;
  16. }

9. Your confirmation form submits your choice, via the _______ method, to ________
a) GET index.php
b) GET admin.php
c) POST index.php
d) POST admin.php

View Answer

Answer: d [Reason:] To process this, you need to add an additional block of code to the top of admin.php that determines what choices you’ve made and act accordingly.

10. When a user confirms that he wishes to delete an entry, that entry’s URL is passed to a function which removes the entry from the __________
a) index.php
b) function.inc.php
c) database
d) admin.php

View Answer

Answer: c [Reason:] If the function is successful, you send the user to the main page. If it fails, you stop execution of the script and display an error, letting the user know that something went wrong.

PHP MCQ Set 3

1. Which directive determines whether PHP scripts on the server can accept file uploads?
a) file_uploads
b) file_upload
c) file_input
d) file_intake

View Answer

Answer: a [Reason:] By default its value is on.

2. Which of the following directive determines the maximum amount of time that a PHP script will spend attempting to parse input before registering a fatal error?
a) max_take_time
b) max_intake_time
c) max_input_time
d) max_parse_time

View Answer

Answer: c [Reason:] This is relevant because particularly large files can take some time to upload, eclipsing the time set by this directive.

3. What is the default value of max_input_time directive?
a) 30 seconds
b) 60 seconds
c) 120 seconds
d) 1 second

View Answer

Answer: b [Reason:] None.

4. Since which version of PHP was the directive max_file_limit available.
a) PHP 5.2.1
b) PHP 5.2.2
c) PHP 5.2.12
d) PHP 5.2.21

View Answer

Answer: c [Reason:] The max_file_limit directive sets an upper limit on the number of files which can be simultaneously uploaded.

5. What is the default value of the directive max_file_limit?
a) 10 files
b) 15 files
c) 20 files
d) 25 files

View Answer

Answer: c [Reason:] None.

6. Which directive sets a maximum allowable amount of memory in megabytes that a script can allow?
a) max_size
b) post_max_size
c) max_memory_limit
d) memory_limit

View Answer

Answer: d [Reason:] Its default value is 16M.

7. If you want to temporarily store uploaded files in the /tmp/phpuploads/ directory, which one of the following statement will you use?
a) upload_tmp_dir “/tmp/phpuploads/ directory”
b) upload_dir “/tmp/phpuploads/ directory”
c) upload_temp_dir “/tmp/phpuploads/ directory”
d) upload_temp_director “/tmp/phpuploads/ directory”

View Answer

Answer: a [Reason:] None.

8. Which superglobal stores a variety of information pertinent to a file uploaded to the server via a PHP script?
a) $_FILE Array
b) $_FILEs Array
c) $_FILES_UPLOADED Array
d) $_FILE_UPLOADED Array

View Answer

Answer: b [Reason:] None.

9. How many items are available in the $_FILES array?
a) 2
b) 3
c) 4
d) 5

View Answer

Answer: d [Reason:] $_FILEs[‘userfile’][‘error’], $_FILEs[‘userfile’][‘name’], $_FILEs[‘userfile’][‘size’], $_FILEs[‘userfile’][‘tmp_name’], $_FILEs[‘userfile’][‘type’] are the five items in the array.

10. Which function is used to determine whether a file was uploaded?
a) is_file_uploaded()
b) is_uploaded_file()
c) file_uploaded(“filename”)
d) uploaded_file(“filename”)

View Answer

Answer: b [Reason:] None.

PHP MCQ Set 4

1. How many predefined variables does PHP use to authenticate a user?
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: b [Reason:] None.

2. Which of the following variables does PHP use to authenticate a user?
i) $_SERVER[‘PHP_AUTH_USER’].
ii) $_SERVER[‘PHP_AUTH_USERS’].
iii) $_SERVER[‘PHP_AUTH_PU’].
iv) $_SERVER[‘PHP_AUTH_PW’].
a) i) and ii)
b) ii) and iv)
c) i) and iv)
d) ii) and iii)

View Answer

Answer: c [Reason:] $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’] store the username and password values, respectively.

3. Which of the following PHP function is commonly used when handling authentication via PHP?
i) header()
ii) footer()
iii) inset()
iv) isset()
a) i) and iv)
b) ii) and iv)
c) ii) and iii)
d) i) and iii)

View Answer

Answer: a [Reason:] None.

4. Which function is used to verify whether a variable contains a value?
a) header()
b) footer()
c) inset()
d) isset()

View Answer

Answer: d [Reason:] The isset() function determines whether a variable has been assigned a value. Its prototype follows: boolean isset(mixed var [,mixed var [,…]]).

5. Which of the following are types of PHP authentication implementation methodologies?
i) Hard-coding a login pair directly into the script
ii) File-based authentication
iii) Data-based authentication
iv) PEAR’S HTTP authentication
a) ii) and iii)
b) i) and iv)
c) ii), iii) and iv)
d) All of the mentioned

View Answer

Answer: d [Reason:] None.

6. 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 login pair directly into the script
b) File-based authentication
c) Data-based authentication
d) PEAR’S HTTP authentication

View Answer

Answer: a [Reason:] This is one of the drawbacks of Hard-coding a login pair directly into the script.

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

View Answer

Answer: b [Reason:] If it is not stored outside, the attacker could discover the file through brute force guessing.

8. 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()

View Answer

Answer: c [Reason:] Although they are similar function, you should use explode() instead of split().In fact split() function has been deprecated altogether.

9. In which of the following situations does file-based authentication become inconvenient.
i) small list
ii) large number of user
iii) users are being regularly added
iv) static authentication
a) i) and iv)
b) i) and iii)
c) ii) and iii)
d) ii) and iv)

View Answer

Answer: c [Reason:] Such requirements are better satisfied by implementing a database based solution.

10. Which is the most powerful authentication method among the four?
a) Hard-coding a login pair directly into the script
b) File-based authentication
c) Data-based authentication
d) PEAR’S HTTP authentication

View Answer

Answer: c [Reason:] It not only enhances administrative convenience and scalability, but also can be integrated into a larger database infrastructure.

PHP MCQ Set 5

1. Which one of the following statements should be used to disable just the fopen(), and file() functions?
a) disable_functions = fopen(), file()
b) disable_functions = fopen, file
c) functions_disable = fopen(), file()
d) functions_disable = fopen, file

View Answer

Answer: b [Reason:] You can set disable_functions equal to a comma-delimited list of function names that you want to disable.

2. Which one of the following statements should be used to disable the use of two classes administrator and janitor?
a) disable_classes = “administrator, janitor”
b) disable_classes = class administrator, class janitor
c) disable_classes = class “administrator”, class “janitor”
d) disable_class = class “administrator”, class “janitor”

View Answer

Answer: a [Reason:] There may be classes inside the libraries that you’d rather not make available. You can prevent the use of these classes with the disable_classes directive.

3. What is the default value of max_execution_time directive? This directive specifies how many seconds a script can execute before being terminated.
a) 10
b) 20
c) 30
d) 40

View Answer

Answer: c [Reason:] This can be useful to prevent users’ scripts from consuming too much CPU time. If max_execution_time is set to 0, no time limit will be set.

4. The memory_limit is only applicable if ___ is enabled when you configure PHP. Fill in the blank.
a) –enable-limit
b) -enable-memory-limit
c) –enable-memory-limit
d) -memory-limit

View Answer

Answer: c [Reason:] This directive specifies, in megabytes, how much memory a script can use. Default value: 128M.

5. Suppose all web material is located within the directory /home/www. To prevent users from viewing and manipulating files such as /etc/password, which one of the following statements should you use?
a) open_dir = “/home/www/”
b) open_dir = /home/www/
c) open_basedir = /home/www/
d) open_basedir = “/home/www/”

View Answer

Answer: d [Reason:] None.

6. Which Apache directive outputs Apache’s server version, server name, port and compile-in modules?
a) ServerSignature
b) ServerName
c) ServerDetails
d) ServerInfo

View Answer

Answer: a [Reason:] It is capable of displaying output like: Apache/2.2.11 (Ubuntu) Server at localhost Port 80.

7. Which directive determines which degree of server details is provided if the ServerSignature directive is enabled?
a) ServerAddons
b) ServerExtra
c) ServerTokens
d) ServerDetails

View Answer

Answer: c [Reason:] Six options are available: Full, Major, Minimal, Minior, OS, and Prod. If it is set to Full ‘Apache/2.2.11 (Ubuntu) PHP/5.3.2 Server’ will be displayed.

8. Which directive should we disable to obscure the fact that PHP is being used on our server?
a) show_php
b) expose_php
c) print_php
d) info_php

View Answer

Answer: b [Reason:] Using the expose_php directive we can prevent PHP version details from being appended on our web server signature. When expose_php is disabled, the server signature will look like: Apache/2.2.11 (Ubuntu) Server.

9. Say I want to change the extension of a PHP file, which of the following statements should I edit to change from .php to .html in the httpd.conf file?
a) AddType application/x-httpd-php .php
b) AddType application/x-httpd-php .asp
c) AddType application/x-httpd-asp .php
d) AddType application/x-httpd-asp .asp

View Answer

Answer: a [Reason:] Just change the .php to .html and your extension will change. This is used for security purpose.

10. The developers of PHP deprecated the safe mode feature as of which PHP version.
a) PHP 5.1.0
b) PHP 5.2.0
c) PHP 5.3.0
d) PHP 5.3.1

View Answer

Answer: c [Reason:] This happened because safe mode often creates many problems as it resolves, largely due to the need for enterprise applications to use many of the features safe mode disables.

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com