Hi there, I am trying to set a cookie on html page with php code, which if cookie is not yet set shows content of a specific Div on that page (in this case it's div called Autoload). But after it's set (which is on next page refresh or reload) I want it to do nothing. I came up with following code, but it wont work... It always displays Div content even if the cookie has been set (or probably because I haven't set it properly). So what I need is: User goes to page, Div content is shown, then on next refresh/reload Div is not shown anymore. What am I doing wrong? Here is the code I've put in the BODY of html page: <?php if(isset($_COOKIE['imekukija'])) { } else { echo ?> <div id="autoload"> <script src="lightbox/prototype.js" type="text/javascript"></script> <script src="lightbox/scriptaculous.js?load=effects" type="text/javascript"></script> <script src="lightbox/lightbox.js" type="text/javascript"></script> <a href="http://www.webmaster-talk.com/images/index_open.jpg" rel="lightbox" id="img"></a> </div> <?php } ?> <?php setcookie("imekukija", "nekiValue", time()+3600); ?> Code (markup):
I'm not positive, but I think you need to use ob_start(); as the very first line of output (before <html>) and ob_flush(); as the final line of output if you aren't sending cookies as the first action.