2
Contributors
1
Reply
10
Views
14 Years
Discussion Span
Last Post by Masterblank
0

jou can use js to set/get/destroy cookies
here is an example

<head>
<script>
/// js function to set a cookie ///
function create_cookie(name, value, days, domain)
{
  var domain_string = domain ? ("; domain=" + domain) : '' ;
  document.cookie = name + "=" + encodeURIComponent( value ) +
      "; max-age=" + 60 * 60 * 24 * days +
      "; path=/" + domain ;
} 
</head>

to set a cookie simply pass your values to create_cookie() function:

create_cookie("bgcolor", "white.png", 365, "your_domain.com"); 


<head>
<script>
/// js function to read a cookie ///
function read_cookie(name)
{
  var str = document.cookie ;
  if (str.length != 0){
    var value = str.match ('(^|;)[\s]*' + name + '=([^;]*)');
    return decodeURIComponent (value[2]) ;
  }
  return '';
}
</script>
</head>

to get a cookie, simply call the function:
var bgcolor = get_cookie("bgcolor");   /// return "white.png"


To destroy the cookie created above:

<head>
<script>
/// js function to destroy a cookie ///
function destroy_cookie(name, domain)
{
  var domain_string = domain ? ("; domain=" + domain) : '' ;
  document.cookie = name + "=; max-age=0; path=/" + domain_string;
}
</script>
</head>

To destroy the cookie simply call the function:
destroy_cookie("bgcolor", "your_domain.com"); 

you can also use php to manipulate cookies, in this case, go here to learn more

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.