<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Check cookies with php</title>
	<atom:link href="http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Fri, 10 Feb 2012 12:12:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Julio</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-868478</link>
		<dc:creator>Julio</dc:creator>
		<pubDate>Mon, 04 Jul 2011 14:19:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-868478</guid>
		<description>What&#039;s wrong with phpinfo()?</description>
		<content:encoded><![CDATA[<p>What&#8217;s wrong with phpinfo()?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-771318</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Sat, 05 Mar 2011 13:28:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-771318</guid>
		<description>Brian, check this one, it works on first page load and subsequent ones.

http://www.pelaphptutorials.com/article/php-checking-to-see-if-a-users-browser-accepts-cookies.html

Also I&#039;m wondering if you need to throw an exit(); after the header redirect?</description>
		<content:encoded><![CDATA[<p>Brian, check this one, it works on first page load and subsequent ones.</p>
<p><a href="http://www.pelaphptutorials.com/article/php-checking-to-see-if-a-users-browser-accepts-cookies.html" rel="nofollow">http://www.pelaphptutorials.com/article/php-checking-to-see-if-a-users-browser-accepts-cookies.html</a></p>
<p>Also I&#8217;m wondering if you need to throw an exit(); after the header redirect?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-727064</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Fri, 14 Jan 2011 09:27:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-727064</guid>
		<description>ok here it is.  this code doesnt work on initial page load

&lt;?php 
setcookie (&#039;test&#039;, &quot;yes&quot;, time() + 60); 
echo &#039;value of $_COOKIE[test]: &#039;.$_COOKIE[&#039;test&#039;].&quot;&quot;;
echo &#039;value of $HTTP_COOKIE_VARS[test]: &#039;.$HTTP_COOKIE_VARS[&#039;test&#039;].&quot;&quot;;
setcookie (&#039;test&#039;, &quot;&quot;, time() + 60);
?&gt;

run that code, and you will get no output, then, comment out the last line;
//setcookie (&#039;test&#039;, &quot;&quot;, time() + 60);

and it takes the first page refresh to load the cookie, then the 2nd page refresh to display the output.  

OK, i hope you guys like this, i got something working here;

&lt;?php
//php cookie check script to warn browser if no cookies are loaded
if(!(isset($_COOKIE[&#039;CHECK&#039;]))){
    if (!(isset($_GET[&#039;COOKIE_TEST&#039;])))
        setcookie (&#039;CHECK&#039;, &quot;cookies are enabled&quot;, time() + 60*60);//do a cookie check once per 1 hour
    //If no error message yet, then do the redirect to load the cookie, otherwise load the error message
    if(!(isset($_GET[&#039;COOKIE_TEST&#039;]))){
        $query = strstr($_SERVER[&#039;REQUEST_URI&#039;],&#039;?&#039;);
        if(!(empty($query))) 
            $newquery = &#039;&amp;&#039;; 
        else
            $newquery = &#039;?&#039; ;
        $string = &#039;COOKIE_TEST&#039;;
        header(&#039;Location: &#039; . $_SERVER[&#039;REQUEST_URI&#039;] . $newquery . $string);
        exit;    
        //setcookie (&#039;test&#039;, &quot;&quot;, time() + 60);
    } else
        echo &#039;&lt;b&gt;You must enable cookies on your browser to use the shopping cart!&lt;/b&gt;&#039;;
} else {
    //echo&#039;cookies are enabled&#039;;
    //echo $_COOKIE[&#039;CHECK&#039;].&quot;&quot;;
    //echo $HTTP_COOKIE_VARS[&#039;CHECK&#039;].&quot;&quot;;
} 
?&gt;</description>
		<content:encoded><![CDATA[<p>ok here it is.  this code doesnt work on initial page load</p>
<p>&lt;?php<br />
setcookie (&#039;test&#039;, &quot;yes&quot;, time() + 60);<br />
echo &#039;value of $_COOKIE[test]: &#039;.$_COOKIE[&#039;test&#039;].&quot;&#8221;;<br />
echo &#8216;value of $HTTP_COOKIE_VARS[test]: &#8216;.$HTTP_COOKIE_VARS['test'].&#8221;";<br />
setcookie (&#8216;test&#8217;, &#8220;&#8221;, time() + 60);<br />
?&gt;</p>
<p>run that code, and you will get no output, then, comment out the last line;<br />
//setcookie (&#8216;test&#8217;, &#8220;&#8221;, time() + 60);</p>
<p>and it takes the first page refresh to load the cookie, then the 2nd page refresh to display the output.  </p>
<p>OK, i hope you guys like this, i got something working here;</p>
<p>&lt;?php<br />
//php cookie check script to warn browser if no cookies are loaded<br />
if(!(isset($_COOKIE[&#039;CHECK&#039;]))){<br />
    if (!(isset($_GET[&#039;COOKIE_TEST&#039;])))<br />
        setcookie (&#039;CHECK&#039;, &quot;cookies are enabled&quot;, time() + 60*60);//do a cookie check once per 1 hour<br />
    //If no error message yet, then do the redirect to load the cookie, otherwise load the error message<br />
    if(!(isset($_GET[&#039;COOKIE_TEST&#039;]))){<br />
        $query = strstr($_SERVER[&#039;REQUEST_URI&#039;],&#039;?&#039;);<br />
        if(!(empty($query)))<br />
            $newquery = &#039;&amp;&#039;;<br />
        else<br />
            $newquery = &#039;?&#039; ;<br />
        $string = &#039;COOKIE_TEST&#039;;<br />
        header(&#039;Location: &#039; . $_SERVER[&#039;REQUEST_URI&#039;] . $newquery . $string);<br />
        exit;<br />
        //setcookie (&#039;test&#039;, &quot;&quot;, time() + 60);<br />
    } else<br />
        echo &#039;<b>You must enable cookies on your browser to use the shopping cart!</b>&#8216;;<br />
} else {<br />
    //echo&#8217;cookies are enabled&#8217;;<br />
    //echo $_COOKIE['CHECK'].&#8221;";<br />
    //echo $HTTP_COOKIE_VARS['CHECK'].&#8221;";<br />
}<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-726982</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Fri, 14 Jan 2011 07:43:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-726982</guid>
		<description>oops, wrong script post, i was referring to this javascript test

http://snippets.bluejon.co.uk/check4-js-and-cookies/check4-js-and-cookie-enabled-v3-phpcode.php

and add the code 
setcookie(&quot;exits&quot;, &quot;&quot;);  
to teh end of teh script.  

no matter what, you need a header() refresh to another page to test if that cookie was active, theres no way to do it in one swipe.</description>
		<content:encoded><![CDATA[<p>oops, wrong script post, i was referring to this javascript test</p>
<p><a href="http://snippets.bluejon.co.uk/check4-js-and-cookies/check4-js-and-cookie-enabled-v3-phpcode.php" rel="nofollow">http://snippets.bluejon.co.uk/check4-js-and-cookies/check4-js-and-cookie-enabled-v3-phpcode.php</a></p>
<p>and add the code<br />
setcookie(&#8220;exits&#8221;, &#8220;&#8221;);<br />
to teh end of teh script.  </p>
<p>no matter what, you need a header() refresh to another page to test if that cookie was active, theres no way to do it in one swipe.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-726980</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Fri, 14 Jan 2011 07:39:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-726980</guid>
		<description>doesnt work, because if you have javascript disabled, then it can never refresh the page, which is what needs to happen in order for the cookie to be read.  the cookie can only be read after its set, and needs a page refresh before its available.  So if the javascript is disabled the cookie might be set, but its not available for the script to test this on one page load.  

in order to see what im talking about, 
add this at the end of your script, which will kill the cookie each time at teh end of the page load for proper testing, 

then disable javascript, leaving cookies enabled, and load the page, you will see only the javascript error, now enable the javascript and you will see the cookie error, each time, until you remove that piece of code.  

to rest for cookies, you will need some kind of header() redirect to load a 2nd page to test for the cookie that was enabled on the first page WHEN javascript is enabled.  

in essence, this script is only valid for cookies when javascript is ENABLED, therefore it is not a valid test for cookies at all, and it mainly useless.</description>
		<content:encoded><![CDATA[<p>doesnt work, because if you have javascript disabled, then it can never refresh the page, which is what needs to happen in order for the cookie to be read.  the cookie can only be read after its set, and needs a page refresh before its available.  So if the javascript is disabled the cookie might be set, but its not available for the script to test this on one page load.  </p>
<p>in order to see what im talking about,<br />
add this at the end of your script, which will kill the cookie each time at teh end of the page load for proper testing, </p>
<p>then disable javascript, leaving cookies enabled, and load the page, you will see only the javascript error, now enable the javascript and you will see the cookie error, each time, until you remove that piece of code.  </p>
<p>to rest for cookies, you will need some kind of header() redirect to load a 2nd page to test for the cookie that was enabled on the first page WHEN javascript is enabled.  </p>
<p>in essence, this script is only valid for cookies when javascript is ENABLED, therefore it is not a valid test for cookies at all, and it mainly useless.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gizzer</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-347452</link>
		<dc:creator>gizzer</dc:creator>
		<pubDate>Tue, 02 Dec 2008 10:02:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-347452</guid>
		<description>all this cookie talk has made me hungry</description>
		<content:encoded><![CDATA[<p>all this cookie talk has made me hungry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-81229</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Fri, 08 Feb 2008 19:23:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-81229</guid>
		<description>Yes, it must be $_COOKIE[&#039;test&#039;]</description>
		<content:encoded><![CDATA[<p>Yes, it must be $_COOKIE['test']</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-73355</link>
		<dc:creator>Graham</dc:creator>
		<pubDate>Sat, 19 Jan 2008 17:17:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-73355</guid>
		<description>Don&#039;t you have to say:

$_COOKIE[&#039;test&#039;]

instead of:

$_COOKIE[test]


I use a lot of PHP and that&#039;s always how I&#039;ve done it.</description>
		<content:encoded><![CDATA[<p>Don&#8217;t you have to say:</p>
<p>$_COOKIE['test']</p>
<p>instead of:</p>
<p>$_COOKIE[test]</p>
<p>I use a lot of PHP and that&#8217;s always how I&#8217;ve done it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SA</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-66613</link>
		<dc:creator>SA</dc:creator>
		<pubDate>Wed, 02 Jan 2008 23:30:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-66613</guid>
		<description>Also i just wanted to say a really easy way to check cookies is with javascripts DOM


if (!navigator.cookieEnabled) { 
		document.write(&quot;No Cookies&quot;);
}else{
		document.write(&quot;Cookies Ok&quot;);
}	
</description>
		<content:encoded><![CDATA[<p>Also i just wanted to say a really easy way to check cookies is with javascripts DOM</p>
<p>if (!navigator.cookieEnabled) {<br />
		document.write(&#8220;No Cookies&#8221;);<br />
}else{<br />
		document.write(&#8220;Cookies Ok&#8221;);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SA</title>
		<link>http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-66602</link>
		<dc:creator>SA</dc:creator>
		<pubDate>Wed, 02 Jan 2008 23:16:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/06/06/check-cookies-with-php/#comment-66602</guid>
		<description>The correct solution would be the first check to make sure the user has Javascript enabled and then check to make sure that cookies are enabled. I would agree with Bryansu that using a client side script rather then a server side script would make more sense and be more reliable.</description>
		<content:encoded><![CDATA[<p>The correct solution would be the first check to make sure the user has Javascript enabled and then check to make sure that cookies are enabled. I would agree with Bryansu that using a client side script rather then a server side script would make more sense and be more reliable.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 6/11 queries in 0.011 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-10 21:25:31 -->
