I have this code
if(isset($_GET['elimina_id'])){
if (in_array($_GET['elimina_id'], $_SESSION['cart']) ) {
$index = (array_keys($_SESSION['cart'], $_GET['elimina_id']));
$i = $index[0];
unset($_SESSION['cart'][$i]);
header('location: cart.php');
}
}
Basically, I want to delete a item in the cart. The thing is, on the test page, localhost, everything works, but on live server I have problems with header(). If I put header() the item won't be deleted, the page only reloads without any action taken effect. If I don't put the header(), after I click the 'Delete item' link, nothing happens, but then if I manually reload the page it works, the item deletes.
On localhost I don't have this problem, what could it be? The php version is OK, could it be some settings in the .ini file ?
Hope you can help me, Thanks
Use ob_start() before header('location: cart.php');
Why not use a meta redirect tag, or a javascript solution?
HTML:
<meta http-equiv="refresh" content="0;url=http://www.site.com/cart.php">
JavaScript #1:
<script>window.location = "http://www.site.com/cart.php";</script>
JavaScript #2: <script>window.navigate("http://www.site.com/cart.php");</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With