CodeIgniter Forums

Full Version: Set php cookie when user closes modal
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 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

<script type="text/javascript">

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

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

    $is_true = true;

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



    if ($cookie == false) {

Try setting the cookie in JavaScript:
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