PG 5
PG 5
2. Understanding
Question: Can you explain the difference between GET and POST methods in PHP?
Solution: The GET method sends data via the URL and appends it to the query string, making it
visible and suitable for non-sensitive data like search queries. The POST method sends data in
the request body, keeping it hidden from the URL and suitable for sensitive data, such as user
credentials. Additionally, POST has a larger capacity for data transfer compared to GET.
3. Applying
Question: How would you implement a basic user login form in PHP?
Solution: To implement a basic user login form in PHP, you would:
php
Copy code
// HTML Form
<form action="login.php" method="post">
<input type="text" name="username" required>
<input type="password" name="password" required>
<input type="submit" value="Login">
</form>
// login.php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Validate and authenticate user
}
4. Analyzing
Question: Analyze the advantages and disadvantages of using a framework like Laravel for PHP
development.
Solution: Advantages:
Disadvantages:
5. Evaluating
Question: Evaluate the impact of using prepared statements in PHP when working with
databases.
Solution: Prepared statements enhance security by preventing SQL injection attacks, which can
occur when untrusted data is used in SQL queries. They improve performance by allowing the
database to optimize the execution plan, especially in cases of multiple executions of similar
queries. However, they may introduce a slight overhead in the initial setup compared to direct
SQL queries.
6. Creating
Question: Design a simple PHP application that stores user comments on a webpage. What
features would you include?
Solution: A simple PHP application for storing user comments could include the following
features:
// submit_comment.php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Validate and insert comment into database
}
Feel free to modify these questions and solutions to fit specific contexts or subject areas!