How can the PHP script be modified to ensure that the cookie is only set after clicking on the banner?

To ensure that the cookie is only set after clicking on the banner, you can modify the PHP script to check if a specific parameter or flag is present in the URL indicating that the banner has been clicked. If the parameter is present, then the cookie can be set. Otherwise, the cookie should not be set.

if(isset($_GET['bannerClicked'])) {
    // Set the cookie here
    setcookie("bannerClicked", "true", time() + 86400, "/");
}