What is the difference between GET and POST methods in PHP?
Why Interviewers Ask This
This is a classic screening question for PHP roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
The GET method sends data appended to the URL as query parameters (?name=Alice&age=25), accessible via $_GET. GET requests are cached, stored in browser history, can be bookmarked, and have URL length limits (around 2048 characters). They should only be used for retrieving data (idempotent operations). The POST method sends data in the HTTP request body, accessible via $_POST. POST data is not visible in the URL, not cached, not stored in browser history, and has no practical size limit. Use POST for submitting forms with sensitive data (passwords), uploading files, or any operation that modifies server state (creating, updating, deleting records).
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a PHP codebase.