How can PHP cookies behave differently on different pages within the same website?

PHP cookies can behave differently on different pages within the same website by setting different parameters such as the cookie path or domain. By specifying unique values for these parameters, you can ensure that the cookie is only accessible on specific pages. Additionally, you can use conditional statements to check for the presence of a cookie on a particular page and adjust its behavior accordingly.

// Set a cookie with a specific path
setcookie('example_cookie', 'value', time() + 3600, '/specific-page');

// Check if the cookie is set on a specific page
if(isset($_COOKIE['example_cookie']) && $_SERVER['REQUEST_URI'] === '/specific-page'){
    // Perform actions based on the cookie's presence
}