Session Variable Doesn't Seem To Work

Hello, I’m working on a cookie notification (a small thing that says that by browsing the page you agree with the new cookie’s law blabla) and when someone closes it (it has a close button) it shouldn’t dispaly anymore when the user changes views. I was thinking to do it with a global variable, so when it’s clicked it sets the variable to false and doesn’t display it. But it does show even though I change the variable to false. Here is the piece of code:


  <?php

 

  if(!isset(Yii::app()->session['cookiesNotify']))


	  {?>

  <div id="cookies">

    <b>you agree with the cooks</a></b>

    <button style="margin-top:5px; margin-right:10px;" class="lebutton" onclick="skrijClick()"><b>SKRIJ</b>   </button>

  </div><!-- cooks -->

  <?php } ?>

and here is the javascript onClick function:


function skrijClick()

  {

	  $( "#cookies" ).hide(); 

	<?php  set( Yii::app()->session['cookiesNotify']) ; ?>


  } 

Any suggestions?

You can’t call PHP code directly from within a JavaScript function. If you want to handle the request in PHP, you need to send an AJAX request to the server.

Assuming that you’re not offering a way to opt out of cookie usage, the easiest option is to do the whole thing in JavaScript and don’t touch the server at all. There are lots of free solutions already built which you can drop straight into your site. Search Google for eu cookie law solutions for some possibilities.