Skip to content

Instantly share code, notes, and snippets.

@sivinnguyen
Last active July 10, 2020 18:04
Show Gist options
  • Save sivinnguyen/ceded97377c7b45bb70936fdce500a06 to your computer and use it in GitHub Desktop.
Save sivinnguyen/ceded97377c7b45bb70936fdce500a06 to your computer and use it in GitHub Desktop.
Safely make A PHP Redirect
<?php
// cs-cart/addons/hybrid_auth/lib/Hybrid/Auth.php
// Ensure session is saved before sending response, see https://github.com/symfony/symfony/pull/12341
if ((PHP_VERSION_ID >= 50400 && PHP_SESSION_ACTIVE === session_status()) || (PHP_VERSION_ID < 50400 && isset($_SESSION) && session_id())) {
session_write_close();
}
// https://www.hostinger.com/tutorials/php-redirect
// https://www.tutorialrepublic.com/faq/how-to-make-a-redirect-in-php.php
// https://upcity.com/blog/6-how-to-redirect-your-site-properly/
// header('Content-type: text/html; charset=utf-8');
header('Location: ' . $url);
exit(); // or die()
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment