Welcome Guest, Not a member yet? Register   Sign In
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


Messages In This Thread
Set php cookie when user closes modal - by wolfgang1983 - 10-19-2017, 02:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB