How can the PHP setcookie() function be used effectively to ensure cookies are properly set and accessible in JavaScript?

When setting cookies using PHP's setcookie() function, it's important to ensure that the cookie is accessible in JavaScript by setting the path parameter to '/' and the domain parameter to the appropriate domain. This will make the cookie accessible across all pages on the domain and allow JavaScript to read its value.

setcookie('cookie_name', 'cookie_value', time() + 3600, '/', 'example.com');