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, '/');
Keywords
Related Questions
- What are some common methods in PHP for finding a specific search term within a webpage's source code?
- In the context of PHP development, why is it important to validate and sanitize user input before processing or storing it in a database?
- How does the IE browser handle the transmission of the Windows username in an Intranet environment, and how can PHP interact with this feature?