Validate emails and URLs in PHP
Use filter_var to validate email addresses and http(s) URLs, with an allow-list for schemes.
Loading snippets…
14 snippets
Use filter_var to validate email addresses and http(s) URLs, with an allow-list for schemes.
Create and verify a timestamped signature over the method, path and body so requests cannot be forged or replayed.
Create UUIDs, random integers in a range and URL-safe tokens with the Web Crypto API instead of Math.random.
Create unpredictable tokens for password resets, API keys and CSRF protection with random_bytes.
A short helper around htmlspecialchars with the right flags for HTML text and attribute values.
Recursively merge configuration objects without mutating the inputs and without prototype pollution.
Turn a sort position into a URL-safe cursor string and validate it when it comes back from the client.
Protect state-changing forms with a per-session token compared in constant time.
Validate an HMAC-SHA256 webhook against the raw request body with a constant-time comparison and replay window.
Validate a signed webhook body with hmac.compare_digest and a timestamp tolerance.
Check a webhook or signed-request HMAC with hash_hmac and hash_equals to avoid timing attacks.
Connect with PDO in exception mode and bind parameters to prevent SQL injection.