What are the differences between using cookies and sessions in PHP for storing data?
When storing data in PHP, cookies and sessions are two common methods. Cookies are stored on the client side and can be accessed by the server for each request, while sessions store data on the server side and assign a unique session ID to the client. Cookies have a size limit and can be manipulated by the client, while sessions are more secure and can store larger amounts of data.
// Using sessions to store data
session_start();
$_SESSION['username'] = 'JohnDoe';
```
```php
// Using cookies to store data
setcookie('username', 'JohnDoe', time() + 3600, '/');