19.2 C
Friday, June 7, 2024

php – What might be inflicting cookies to not work on IOS?

I constructed a bit banner that seem on the prime of the web page till the person closes it. As soon as closed, it shouldn’t present once more for twenty-four hours. I’ve tried to take action utilizing cookies – when the person x’s out the banner, a cookie known as “close_mobile_banner” with the date as the worth is saved for twenty-four hours. That is engaged on desktop, however not IOS (I have never tried different OS’s). When the person closes the banner on IOS, it seems once more when the web page is refreshed (needs to be hidden for twenty-four hours).

header.blade.php (it is a blade template – it is principally PHP with just a few variations)

Be aware – I simplified the code a bit so it is simpler to skim. This code is totally useful (simply not on ios..)

@if (!isset($_COOKIE['close_mobile_banner']))
        $bg_color         = get_sub_field('background_color');
        $text_color       = get_sub_field('text_color');
        $copy             = get_sub_field('copy');

      <div class="mobile-banner" type="background-color: {{ $bg_color }}; shade: {{ $text_color }}">
        <div class="wrapper">
          <p class="mobile-banner-copy">{{ $copy }}</p>
          <a href="{{ $google_play_link }}" class="android-image mobile-banner-image">
            <svg width="108" top="32" viewBox="0 0 108 32" fill="none" xmlns="http://www.w3.org/2000/svg"></svg>
          <button class="mobile-banner-close" onclick="occasion.preventDefault();$(this).closest('.mobile-banner').removeClass('lively'); setCookie('close_mobile_banner', new Date().toISOString(), 1)"></button>


perform setCookie(cname, cvalue, exdays) {
    const d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    let expires = "expires="+d.toUTCString();
    doc.cookie = cname + "=" + encodeURIComponent(cvalue) + ";" + expires + ";path=/";

// debugging 
perform getCookie(title) {
  const worth = `; ${doc.cookie}`;
  const elements = worth.break up(`; ${title}=`);
  if (elements.size === 2) return elements.pop().break up(';').shift();

It is a WordPress web site, utilizing Blade/Laravel, Superior Customized Fields, and checking on an iPhone SE (Safari and Chrome).

Latest news
Related news


Please enter your comment!
Please enter your name here