Hi guys, Will this php code work for checking if cookies are enabled? setcookie('test', 1, time()+3600); if(count($_COOKIE) > 0){ //enabled } else { //not enabled } PHP: If not, what would? Thanks, -Tony Note: Original, unedited code from http://nik.chankov.net/2010/01/16/detecting-if-the-cookies-are-enabled-with-php/
Well, seems that it somewhat works.... Somewhat, because even if cookies are enabled, the first time someone visits your site, it says that cookies are disabled (even if the are enabled).. Let's fix that..It's an easy fix... First we create a cookie <?php setcookie('test', 1, time()+3600); ?> PHP: (Note: this should be the first thing on your site - even before the doctype, else it'll throw a warning that headers are already sent) next, we check if there is a cookie with the isset() function <?php if (isset($_COOKIE['test'])) { echo("enabled"); } else { echo("disabled"); } ?> PHP: Have fun