Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 30-10-2009
Member
 
Join Date: Sep 2009
Posts: 135
How to create a cookie

I lost in the vast Internet resources. Some offer a full paragraph, other 2 lines but does not offer what I want to do etc. I would like a cookie. Preferably in php. The smallest possible and simple cookie that prevents the activation of a javascript if it has already been run once on all of my site. For example with the following code:
HTML Code:
<script>
alert('This script is repeated on every page of my site but do not view that once during the session of the surfer);
</script>
Could you help me?
Reply With Quote
  #2  
Old 30-10-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: How to create a cookie

You set a cookie and put a value to "false", for example

after you make a condition

Code:
if($_COOKIE['hello'] == false)
{
 echo 'your script';
setcookie('hello', true);
 

}
Reply With Quote
  #3  
Old 30-10-2009
Member
 
Join Date: Sep 2009
Posts: 135
Re: How to create a cookie

Thank you for your answer

The following simple code does not work on my php page.
PHP Code:
<?php
setcookie
('MyCookie''false', (time() + 3600));
?>
<script>
if($_COOKIE['MyCookie'] == false)
{
alert('this message will pop 1000 times!')
setcookie('MyCookie', true);
}
</script>
Can you help me to fix it?
Reply With Quote
  #4  
Old 30-10-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: How to create a cookie

You mixed up php and javascipt:

PHP Code:
<?php
setcookie
('MyCookie''false', (time() + 3600));
?>
<script>
<?php
if($_COOKIE['MyCookie'] == false):
?>
alert('this message will pop 1000 times!')
<?php
setcookie
('MyCookie'true);
endif;
?>
</script>
and after that, you can manage cookies in javascript and repeat the same code in a cleaner way
HTML Code:
<script type="text/javascript">
  if(!document.cookie)
  {
   alert("first" );
   document.cookie = 'visited';
  }
 </script>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to create a cookie"
Thread Thread Starter Forum Replies Last Post
How to use ASP to maintain the cookie Anirvinya Software Development 5 16-02-2010 03:38 AM
How to Create a Cookie in PHP? sivaranjan Software Development 4 27-01-2010 10:53 PM
what is cookie in java? Jabeen Software Development 3 21-11-2009 02:53 PM
LG Cookie applications B e B o Portable Devices 2 21-09-2009 12:52 PM
What is a Cookie? Dharmavira Technology & Internet 5 18-02-2009 12:33 PM


All times are GMT +5.5. The time now is 03:25 PM.