Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problem with creating cookie and showing/hiding div based on it...
Old 04-24-2009, 02:57 PM Problem with creating cookie and showing/hiding div based on it...
Novice Talker

Posts: 9
Trades: 0
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:


Code:
<?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);
 ?>
Error404 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-24-2009, 03:02 PM Re: Problem with creating cookie and showing/hiding div based on it...
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
The cookie needs to be set before you send any HTML as it set itself via a header request.

If you can't set your cookie before you send HTML, take a look at setting cookies via JavaScript.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Reply     « Reply to Problem with creating cookie and showing/hiding div based on it...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15411 seconds with 12 queries