Skip to content
Snippets

Snippet Library

Practical pure PHP patterns that are easy to study, adapt and use.

Code

Set a Cookie

Sets a cookie with explicit expiry, path, secure, HttpOnly, and SameSite options when headers are still open.

Open Snippet
Code

Custom Error Handler

Registers a temporary custom error handler that captures safe error details into an array and restores the previous handler.

Open Snippet