/    Sign up×
Community /Pin to ProfileBookmark

cookies on java script problems

here is the code.

// JavaScript Document
function checkCookie(){
setCookie(true);
if (document.cookie==null||document.cookie==””){
setCookie(true);
return “visitor”;
}
if (getCookie(“/login/”)==”no”) return “visitor”;
return getCookie(“/username/”);
}

function setCookie(newuser){
var expire_date = new Date();
expire_date.setDate(expire_date.getDate()+1);
if (newuser) document.cookie = “mycookie=name; login=no; username=ben; expires=” + expire_date.toGMTString();
}

function getCookie(field){
var str = “”;
for (var i=document.cookie.search(field)+field.length-1 ;
i<document.cookie.length ;
i++){
if (document.cookie[i]==”;”)
break;
str += document.cookie[i];
}
return str;
}

can’t make it work and fing the regular expresions /login/ in the cookie and also /username/
why is that? someone can make it work?
thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Y_LessMay 24.2009 — "/login/" is a string /login/ is a regular expression. If you want to make a regular expression from a string you need "new RegExp(str)", alternatively, just pass a real regular expression to the function.
Copy linkTweet thisAlerts:
@GueztauthorMay 24.2009 — thanks, but still not working i think its stop to look for the regular expression after the "; " and i dont know why.

tried escape and also not working.
×

Success!

Help @Guezt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...