here i came across a weird problem. I have a shopping cart and I want every page of my website to display the number of items in cart. I am adding the code below:
<?php
session_start();
if (!isset($_SESSION['SHOPPING_CART'])){ $_SESSION['SHOPPING_CART'] = array(); }
$totalItems = is_array($_SESSION['SHOPPING_CART']) ? count($_SESSION['SHOPPING_CART']) : 0;
?>
The code works perfectly on the cart page that shows all the items added, but NOT on any other page. And one more thing, the above code works perfectly on XAMPP and not on the web server. Here is the error I am getting:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at index.php:1) in index.php on line 2
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at index.php:1) in index.php on line 2
So what may the possible reason? something to do with php version on server? if so, why its working on cart page?