FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Javascript, cookies, Opera; PROBLEM

 


animassacre
I'm using JS to set a cookie. But in Opera something strange happens -- the cookie is not accessabele (in PHP) from other directories then the root and this is only in Opera.

This is the script I'm using:
Code:
         
var exdate=new Date();
            exdate.setDate(exdate.getDate()+356);
            document.cookie="val=" +escape(val)+
            ";expires="+exdate.toGMTString()+
            location.href=location.href;


PLS help me

ps: I tryed ";path=/"; and ";domain= .... but it's still the same
Marcuzzo
http://www.w3schools.com/PHP/php_cookies.asp


This is an example they use to set a cookie
Code:
<?php
setcookie("user", "Alex Porter", time()+3600);
?>
[/url]
Naif
animassacre,

Try using the following JavaScript function. It's what I use most of the time

Code:

function set_cookie(name,value,expires,path,domain,secure) {
   var today=new Date();
   today.setTime(today.getTime());

if (expires) {
  expires = expires;
}

var expires_date = new Date( today.getTime() + (expires));

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
}


An example of it's usage is as follows:

Code:

set_cookie('name', 'value', 60*60*24, '/', '', '');


The 60*60*24 specifies when you want it to expire. 60*60*24 means in 24 hours.

Let me know if that works for you.

Regards,
-- Naif
Marcuzzo
the JS function naif presented is correct but I'm pretty sure that this is not the issue.
I believe the question was:

Quote:
I'm using JS to set a cookie. But in Opera something strange happens -- the cookie is not accessabele (in PHP) from other directories then the root and this is only in Opera.

this looks more like a PHP issue.

I allready suggested the PHP Cookies page on W3Schools, if this didn't help you can allways check the PHP: Set Cookie Manual, they mention opera at several occasions
Related topics

PHP and cookies. Simple problem.
Opera Problem
embedding javascript menu simple problem
Opera anomaly, Flash Gallery+XML, Problem, HELP?! [SOLVED]
Free Opera registration - surf without ads - only today!

Opera Nao abrindo Recados do Orkut
Remember form Data HTML
Who hates PDFs?
favourites picture
Javascript, Display Cookie.

javascript screen.width problem
A network with everything in it
math problem with javascript
[New Problem] Opera and absolute Div's
JavaScript problem in IE7
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.