Set cookie by clicking on a link

You can’t. PHP runs on the server, not in the browser. You need to use JavaScript for this.