Web Programming Website And Web Server Programming 2 — Questions and Answers
Question 1: Which HTTP status code indicates that a requested resource has been permanently moved to a new URL?
- 301 Moved Permanently (Correct answer)
- 302 Found
- 304 Not Modified
- 307 Temporary Redirect
Correct answer: 301 Moved Permanently
301 tells clients and search engines that the resource has permanently moved, updating their cached URL.
Question 2: In Apache configuration, which directive restricts access to a directory based on the client's IP address?
- Require ip (Correct answer)
- AllowIP
- Restrict
- IPFilter
Correct answer: Require ip
The 'Require ip' directive inside a <Directory> or <Location> block controls IP-based access in Apache 2.4+.
Question 3: What does the PHP function `session_start()` do when called at the top of a script?
- Initializes or resumes a session using a session cookie (Correct answer)
- Creates a new database connection
- Starts an HTTP keep-alive connection
- Opens a file upload stream
Correct answer: Initializes or resumes a session using a session cookie
session_start() reads the session ID from a cookie (or URL), loads stored session data into $_SESSION, or creates a new session if none exists.
Question 4: Which Node.js module provides the built-in HTTP server functionality without any third-party packages?
- http (Correct answer)
- express
- net
- server
Correct answer: http
The built-in 'http' module lets you create an HTTP server with http.createServer() without installing any packages.
Question 5: In a RESTful API, which HTTP method is conventionally used to partially update an existing resource?
- PATCH (Correct answer)
- PUT
- POST
- UPDATE
Correct answer: PATCH
PATCH applies partial modifications to a resource, whereas PUT replaces the entire resource representation.
Question 6: What is the purpose of a `.htaccess` file placed in a web directory on an Apache server?
- Provides directory-level configuration overrides without restarting Apache (Correct answer)
- Stores encrypted user passwords for the OS
- Defines PHP include paths globally
- Configures SSL certificates for the virtual host
Correct answer: Provides directory-level configuration overrides without restarting Apache
.htaccess files allow per-directory configuration such as URL rewrites, authentication, and MIME types without modifying the main server config.
Question 7: Which SQL injection prevention technique uses parameterized queries in server-side code?
- Prepared statements (Correct answer)
- Input trimming
- URL encoding
- HTML escaping
Correct answer: Prepared statements
Prepared statements separate SQL logic from data so user input is never interpreted as SQL commands.
Which HTTP status code indicates that a requested resource has been permanently moved to a new URL?