Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14343

Set php cookie when user closes modal

$
0
0
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>

Viewing all articles
Browse latest Browse all 14343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>