What are the potential pitfalls of using the header() function in PHP for redirection within a login system?
Using the header() function for redirection within a login system can lead to potential security vulnerabilities, such as header injection attacks. To mitigate this risk, it is recommended to use the header("Location: ") function with an absolute URL and exit the script immediately after redirection.
// Redirect user to dashboard after successful login
if ($login_successful) {
header("Location: https://example.com/dashboard.php");
exit;
}