Jump to content

Recommended Posts

hi, i have this line of PHP

 

<?php if(strstr($_COOKIE['contact_ids'], $row['ID']) !== FALSE){echo 'checked';}?>

 

it works fine, but needs a page reload to show the changes.

 

does anyone know how i can achieve this effect in jQuery? particularly the strstr() function. thanks again!

Link to comment
https://forums.phpfreaks.com/topic/246137-change-a-line-of-php-into-jquery/
Share on other sites

That's because PHP doesn't actually create a cookie. When you set it, PHP adds a header to the response it sends back to the browser at the end of execution. When the browser receives this header it then creates the cookie, so effectively you have to wait until the next request. What you can do, is at the point of creating the cookie, manually add it to the $_COOKIE array:

 

setcookie(...);
$_COOKIE['...'] = '...';

Yep that makes perfect sense - I thought you were talking about a different problem. jQuery doesn't have native support for cookies (though there are plug-ins). Vanilla JS isn't that easy to work with them either. Instead of a nice clean array like in PHP, you have a string with the cookies separated by a semi-colon, which you access through document.cookie. Which route would you like to take?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.