JKG Posted August 31, 2011 Share Posted August 31, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/246137-change-a-line-of-php-into-jquery/ Share on other sites More sharing options...
Adam Posted September 1, 2011 Share Posted September 1, 2011 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['...'] = '...'; Quote Link to comment https://forums.phpfreaks.com/topic/246137-change-a-line-of-php-into-jquery/#findComment-1264201 Share on other sites More sharing options...
JKG Posted September 1, 2011 Author Share Posted September 1, 2011 the php script and everything to do with the cookie works fine. just with the nature of php, it needs the page to load. however with jquery, i can determine whats in the cookie in real time. does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/246137-change-a-line-of-php-into-jquery/#findComment-1264202 Share on other sites More sharing options...
Adam Posted September 1, 2011 Share Posted September 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/246137-change-a-line-of-php-into-jquery/#findComment-1264211 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.