Connect the html button to the php code to do something

I want to connect my HTML code to PHP that when you click on a specific button in a message, do these: 1- set a cookie that don't show it again. 2- hide messages with CSS. And when user come back to my site read cookie and don't show message.

Answer

Solution:

Cookies are part of the HTTP requests. When you request a URL it can respond with set-cookie header. The browser read this and changes the cookies.

So, If you want to change a cookie, this must be done by PHP.

Let's have a button.

<a href='dontshowagain.php'>Dont show again</a>

And, PHP code,

setCookie("hideAnnounce", "1"); // add the cookie to response
header("location: /index.php"); // add redirection to response

Now, index.php can read the cookie.

<?php if(!isset($_COOKIE['hideAnnounce'])){ ?>
   <div>announcement</div>
<?php } ?>

Source