
Q91
Q91 What is the primary purpose of cookies in web development?
To store server data
To store client-side, persistent user data
To improve network speed
To encrypt data
Q92
Q92 How are PHP sessions different from cookies?
Sessions are stored on the client-side, while cookies are stored on the server-side
Sessions and cookies are the same
Sessions are stored on the server-side, while cookies are stored on the client-side
Sessions encrypt data automatically
Q93
Q93 In PHP, what function is used to start a session?
session()
session_start()
start_session()
begin_session()
Q94
Q94 What is a session hijacking attack?
An attack where the attacker steals the session cookie
An attack where the server hijacks a client's session
A brute force attack
A SQL injection attack
Q95
Q95 How can you increase the security of PHP sessions?
By using SSL and storing sessions in a database
By increasing the session timeout
By disabling cookies
By using longer session IDs
Q96
Q96 What will be the output of the following PHP code?
setcookie("user", "John Doe", time() + 3600); echo $_COOKIE["user"];
John Doe
An error
Nothing
The current time + 3600
Q97
Q97 In PHP, how can you delete a cookie?
By setting its value to null
By using the delete_cookie() function
By setting its expiration date in the past
By unsetting it in $_COOKIE
Q98
Q98 Consider this PHP code:
session_start();
$_SESSION['user'] = 'Alice'; session_destroy();
echo $_SESSION['user'];
What is output?
Alice
An error
Nothing
The session ID
Q99
Q99 Identify the error in this PHP cookie code:
setcookie("user", "Alice", time() - 3600);
The cookie is being set with a past expiration time
The cookie value is incorrect
There is no error in the code
The cookie name is incorrect
Q100
Q100 Spot the mistake in this PHP session handling code:
session_start(); $_SESSION = array(); session_destroy();
Not using session_unset() before session_destroy()
Incorrect use of session_start()
No mistake
The session array should not be emptied
Q101
Q101 What is the main advantage of using a PHP framework like Laravel or Symfony?
Standardized coding practices
Faster execution of scripts
Automatic HTML parsing
Increased PHP script size
Q102
Q102 How does the MVC (Model-View-Controller) architecture in frameworks like Laravel and Symfony benefit web application development?
It enhances the UI/UX design
It speeds up the database read/write operations
It separates business logic, presentation, and data access
It reduces server load
Q103
Q103 In Laravel, what is a "Route" used for?
To optimize database queries
To create links to different pages
To define URLs and their corresponding actions in the application
To manage user sessions
Q104
Q104 Given a Laravel blade template, how can you display a variable passed from a controller?
Q105
Q105 In Symfony, what is the purpose of a "Service Container"?
To manage user authentication
To store and retrieve session data
To automatically inject dependencies into classes
To handle database migrations
Q106
Q106 Identify the issue in this Symfony controller method:
public function index() {
return $this->render('index.html.twig');
}
The method doesn't specify a route
The template file extension should be .blade.php
The method must return a Response object
No issue in the code
Q107
Q107 Spot the mistake in this Laravel Eloquent query:
$users = User::where('age', '>', 30)->get();
The get() method is used incorrectly
The where clause is incorrect
There is no mistake
The model User is likely not defined
Q108
Q108 What is a RESTful API in the context of web services?
An API that uses XML for data exchange
An API that allows only GET requests
An API designed around the principles of REST (Representational State Transfer)
An API that requires SOAP protocol
Q109
Q109 What is the primary role of JSON in web services developed with PHP?
To structure the layout of a web page
To act as a query language for databases
To format and transfer data between client and server
To encrypt data during transmission
Q110
Q110 How can you send a JSON response from a PHP script?
json_encode()
json_response()
header("Content-Type: application/json"); echo json_encode($data);
send_json($data);
Q111
Q111 In PHP, how can you consume a RESTful API using cURL?
Using file_get_contents() with the API URL
Using the cURL functions to make a request and receive a response
Using JSON encoding and decoding
Using simple XML loading functions
Q112
Q112 Identify the common error in this API request code in PHP:
$response = file_get_contents('https://api.example.com/data');
Not checking for a false response
Incorrect URL format
Not setting a user agent
The function file_get_contents cannot be used for API requests
Q113
Q113 Spot the mistake in this PHP code for sending a POST request using cURL:
curl_setopt($ch, CURLOPT_POST, true); curl_exec($ch);
Not setting the CURLOPT_POSTFIELDS option
The CURLOPT_POST option is incorrectly used
curl_exec() is used incorrectly
No mistake in the code
Q114
Q114 What is the significance of using the PHP Data Objects (PDO) extension for database access?
It provides faster query execution
It is specific to MySQL databases
It offers a secure, consistent way to interact with different databases using the same interface
It automatically creates database schemas
Q115
Q115 Why is it recommended to avoid using the PHP closing tag ?> at the end of a file?
To prevent syntax errors
To improve performance
To prevent accidental whitespace or new lines after the tag, which can cause output buffering issues
To conform to PSR standards
Q116
Q116 In PHP development, what is the purpose of using a coding standard like PSR (PHP Standards Recommendations)?
To enforce a specific framework's best practices
To ensure compatibility with PHP versions
To standardize coding style and practices for better readability and maintainability
To optimize performance
Q117
Q117 What is the best practice for handling errors in PHP to maintain code readability and manageability?
Using die() or exit() statements
Suppressing errors with the @ operator
Implementing structured exception handling with try-catch blocks
Logging errors to a file and displaying a generic error message to the user
Q118
Q118 How should sensitive configuration information (like database credentials) be managed in PHP applications?
Hardcoded in the PHP files
Stored in a separate configuration file and ignored from version control systems
Stored in the database
Encoded and embedded within the code
Q119
Q119 Identify the best practice when naming variables and functions in PHP.
Using short, non-descriptive names for brevity
Using all-uppercase letters for clarity
Using meaningful, descriptive names following a consistent naming convention
Varying naming conventions throughout the application
Q120
Q120 What is a common pitfall to avoid when using global variables in PHP?
Using them to store user input directly
Declaring them in every file
Using them extensively throughout the application
Initializing them in every function

