What is the correct syntax for setting a cookie in PHP?

To set a cookie in PHP, you need to use the setcookie() function. This function takes several parameters including the cookie name, value, expiration time, path, domain, secure flag, and httponly flag. It's important to note that you should set cookies before any output is sent to the browser.

// Set a cookie with name 'user' and value 'John Doe' that expires in 1 hour
setcookie('user', 'John Doe', time() + 3600, '/');