Extra code after html tag causes error message
I am sorry, if this is a duplicate post. I thought I posted it, but I couldn't find it.
I had the problem, that after the final step of the checkout process the cart was not emptied. Jason sent me this code to add after the html tag:
<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
// Finally, destroy the session.
session_destroy();
?>
Now the cart is empty after the success page is displayed, but there appears an error message on the success page:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/www.name.de/web/shop/checkout_success.php:22) in /var/www/html/www.name.de/web/shop/checkout_success.php on line 305
Line 305 of the success page is: setcookie(session_name(), '', time()-42000, '/');
This is part of the code that I added after the html tag.
Despite the error message everything works. How do I get rid of that error message?