What are the advantages and disadvantages of using SESSION, COOKIE, or Web Storage for storing cart content in PHP?
Storing cart content in PHP can be done using SESSION, COOKIE, or Web Storage. SESSION is a server-side storage mechanism that keeps data on the server, COOKIE stores data on the client-side, and Web Storage stores data on the client-side as well but with larger storage capacity. SESSION is secure but can be slower, COOKIE has size limitations and potential security risks, while Web Storage is fast and has more storage capacity but is not supported in older browsers.
// Storing cart content using SESSION
session_start();
$_SESSION['cart'] = array('item1', 'item2', 'item3');
```
```php
// Storing cart content using COOKIE
$cartItems = array('item1', 'item2', 'item3');
setcookie('cart', serialize($cartItems), time() + 3600, '/');
```
```php
// Storing cart content using Web Storage
echo '<script>';
echo 'localStorage.setItem("cart", JSON.stringify(["item1", "item2", "item3"]));';
echo '</script>';