• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set php cookie when user closes modal

#1
I want to be able to set at cookie in php when the user closes a bootstrap modal.

And so when user comes back to that page one show again until cookie expire. 

For some reasons still sets the cookie.

I am not sure how to use local.storage properly for this.

How to make is so when user comes to home page the modal will show and once the user closes modal it will set cookie and stop modal from showing until cookie expire.

Thank you

Code:
<script type="text/javascript">

$cookie = "<?php echo $_COOKIE['alert_modal'];?>";

$(document).on('click', '#close_model', function (e) {
     <?php

    $is_true = true;

    setcookie('alert_modal', $is_true , time() + (86400 * 7)); // 86400 = 1 day

    ?>

});

$(window).on('load',function(){
    if ($cookie == false) {
       $('#myModal').modal('show');
    }
});    

</script>
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
Try setting the cookie in JavaScript:

https://www.w3schools.com/js/js_cookies.asp
Reply

#3
jQuery cookie is no longer maintained.

It has been replaced with JS Cookie which doe's not require jQuery

A simple, lightweight JavaScript API for handling browser cookies
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.