How can developers prevent or fix the issue of cross-site-cookies in PHP?

Cross-site cookies can be prevented or fixed in PHP by setting the "SameSite" attribute in the cookie to "Strict" or "Lax". This attribute restricts the cookie from being sent in cross-site requests, thus preventing potential security vulnerabilities like CSRF attacks.

// Set cookie with SameSite attribute
setcookie('cookie_name', 'cookie_value', [
    'expires' => time() + 3600,
    'path' => '/',
    'domain' => 'example.com',
    'secure' => true,
    'httponly' => true,
    'samesite' => 'Strict'
]);