Skip to content

Web · updated 26 November 2026

PHP runs a large share of websites and content systems. These scenarios cover security, performance and modern practices.

Top 10 PHP scenario questions

Try each one yourself first, then open the model answer.

1. A login query builds SQL by concatenating user input. What is the risk and fix?

Show answer

SQL injection. Use prepared statements with bound parameters through PDO or your framework's query builder.

2. How should user passwords be stored?

Show answer

With password_hash using a modern algorithm and checked with password_verify. Never use MD5 or SHA-1, and rehash on login when settings change.

3. A page is slow because it runs one query per product in a list. What do you do?

Show answer

Fetch related data in one query or use eager loading in your ORM, and add indexes for the columns you filter on.

4. Users can upload profile pictures. How do you keep that safe?

Show answer

Check size and real content type, generate your own file name, store outside the web root or disable script execution in the upload folder, and re-encode images.

5. A form can be submitted from another website on behalf of a logged-in user. How do you prevent it?

Show answer

Add a CSRF token to state-changing requests and set cookies with SameSite, HttpOnly and Secure.

6. A report script exceeds the maximum execution time. What is the better design?

Show answer

Move it to a background queue or scheduled job, process in chunks, and let the user download the result when it is ready.

7. Comparing a password reset token with == behaves strangely. Why?

Show answer

Loose comparison can convert types in surprising ways and leaks timing. Use hash_equals for secrets and === elsewhere.

8. Memory runs out while exporting a large table. How do you fix it?

Show answer

Stream results with an unbuffered query or chunking, and use generators to write rows as you go.

9. You inherit a site on an unsupported PHP version. What is your plan?

Show answer

Back up, add tests for key flows, update dependencies, run a compatibility checker, upgrade on a staging copy, then deploy with a rollback plan.

10. Error messages with file paths appear to visitors. What should be configured?

Show answer

Turn display_errors off in production, log errors instead, and show a friendly error page.

Ready to build something great?

Book your free 30-minute consultation today. No obligation, just honest advice.