What is the difference between setcookie() and session_start() in PHP?

setcookie() is used to set a cookie in the user's browser, while session_start() is used to start a session and store session data on the server. Cookies are stored on the user's browser and can be accessed by the client-side, while session data is stored on the server and is more secure. If you need to store sensitive information or data that should not be accessible by the client-side, use session_start().

<?php
// Using setcookie() to set a cookie
setcookie("user", "John Doe", time() + 3600, "/");

// Using session_start() to start a session
session_start();
$_SESSION['user'] = "John Doe";
?>