Home »
Aptitude Questions and Answers »
PHP Aptitude Questions and Answers
PHP Sessions Aptitude Questions and Answers
PHP Sessions Aptitude: This section contains aptitude questions and answers on Sessions.
By Nidhi Last updated : December 15, 2023
This section contains Aptitude Questions and Answers on PHP Sessions.
1) There are the following statements that are given below, which of them are correct about the session in PHP?
- A session is used to store information that can be accessed by the multiple pages of a web application.
- The session values are stored in the user's computer.
- The session variable store the values related to the single user.
- The session variable store the values related to multiple users.
Options:
- A and B
- A and C
- A, B, and C
- A, B, and D
Correct answer: 2
A and C
Explanation:
A session is used to store information that can be accessed by the multiple pages of a web application. It is used to store values related to a single user only.
2) Which of the following function is used start a session in PHP?
- start_session()
- startsession()
- session_start()
- sessionstart()
Correct answer: 3
session_start()
Explanation:
The session_start() function is used to start a session in PHP.
3) Can we save data permanently using session variables?
- Yes
- No
Correct answer: 2
No
Explanation:
No, the session does not store data permanently, it stores data that can be accessed on different pages of web application during a login session. If you want to store data permanently then you can use files and databases.
4) When a PHP session expires by default?
- After 10 minutes
- After 15 minutes
- When we close the browser
- None of the above
Correct answer: 3
When we close the browser
Explanation:
The session got expire when we close the browser.
5) In a computer can we create two sessions of the same web application?
- Yes
- No
Correct answer: 1
Yes
Explanation:
Yes, we can create two or more than two sessions of the same web application by opening web applications on different browsers like Mozilla Firefox, Internet Explorer, Google Chrome, etc.
6) Which is the correct way to save the value in a session in PHP?
- Using set_session() function
- Using setsession() function
- Using $_SESSION superglobal variable
- None of the above
Correct answer: 3
Using $_SESSION superglobal variable
Explanation:
The $_SESSION superglobal variable is used to set session value like this:
$_SESSION["color"] = "GREEN";
Here, color is the session name and "GREEN" is the value.
7) Which of the function is used to print all values stored in session variables?
- printSession()
- printAllSession()
- print_r()
- None of the above
Correct answer: 3
print_r()
Explanation:
The print_r() function is used to print all values stored in the session variables. The function call is given below:
print_r($_SESSION);
8) To modify the value of the session variable, we need to use any special function?
- Yes
- No
Correct answer: 2
No
Explanation:
To modify the value of the session variable, there is no need for any special function, we can modify values just assigning a new value.
$_Seession["color"] = "RED";
9) Which of the following function is used to remove all session variables?
- session_unset()
- remove_sessions()
- remove_all_sessions()
- delete_all_sessions()
Correct answer: 1
session_unset()
Explanation:
The session_unset() function is used to remove all session variable.
10) Which of the following function is used to destroy session in PHP?
- session_destroy()
- destroy_session()
- destroysession()
- sessiondestroy()
Correct answer: 1
session_destroy()
Explanation:
The session_destroy() function is used to destroy session in PHP.