CodShot
PHP Public

Safe Redirect Allow List

Redirect only to known internal paths instead of trusting user input.

#php #redirect #security #validation
PHP
<?php

$allowedRedirects = [
    '/my-dashboard',
    '/my-workspace',
    '/my-billing',
];

$next = $_GET['next'] ?? '/my-dashboard';

if (!in_array($next, $allowedRedirects, true)) {
    $next = '/my-dashboard';
}

header('Location: ' . $next);
exit;

Notes

Avoid open redirects by allowing only known local paths.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support