No longer display advertising case (php operations cookie)

1, page structure is simple to build

  ad.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            height:100px;
            background-color: #e0daff;
        }
        div > a{
            float:right;
        }
    </style>
</head>
<body>
<div>
    <a href="">不再显示广告</a>
</div>
</body>
</html>

2, a way to create a page close.php

 ad.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            height:100px;
            background-color: #e0daff;
        }
        div > a{
            float:right;
        }
    </style>
</head>
<body><?php if (empty($_COOKIE['hide_ad']) || $_COOKIE['hide_ad'] !== '1'): ?>
<div>
    <a href="close.php "> no longer display ads </a> 
<? PHP endif?>
</ div>

</body>
</html>

close.php (as long as someone to ask me, this means that people do not want to see ads, we'll give this user opened a small ticket)

<?php

    setcookie('hide_ad', '1');
    header('Location: ad.php');

 

3, two way, mass participation

 ad.php

<?php
    if(isset($_GET['action']) && $_GET['action'] === 'close-ad'){
        setcookie('hide_ad' , '1');
        $_COOKIE['hide_ad'] === '1';
    }
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            height:100px;
            background-color: #e0daff;
        }
        div > a{
            float:right;
        }
    </style>
</head>
<body>
 <?php if (empty($_COOKIE['hide_ad']) || $_COOKIE['hide_ad'] !== '1'): ?>
<div>
    <a href="ad.php?action=close-ad">No longer display advertising </a> 
</ div>
<? PHP endif?>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/shanlu0000/p/11616088.html