Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Cookie help needed on user recognition

Posted on 2001-09-13
7
Medium Priority
?
212 Views
Last Modified: 2013-12-18
Could someone please help me! I have a discussion forum application, and my customer would like for users to be "remembered" when the revisit the site after registering and  logging in for the first time.

I can't really manipulate the Custom Login form because this is form that is used for all our applications on that server. So I am trying to write a cookie or something that will do the task.
What happens now is when a user registers, after they get confirmation of the username and password they chose, they are redirected to the $$ViewTemplateDefault form, and I have the &Login parameter attached. This way, they are prompted to login right away. This is the form they also come back to when visiting the site subsequently, but they aren't prompted to login on a revisit. I would like to set it up so that when a user comes back to the $$ViewTemplateDefault form, a message displays saying "Welcome Back" and their username. But I still want them to login in order to post a message or  respond to one. I just want the cookie to store the username. Any ideas on how I would do that with a JavaScript cookie? Or is there a Notes way to do this?

Any help would be greatly appreciated.
0
Comment
Question by:mfay72
  • 4
  • 3
7 Comments
 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 400 total points
ID: 6479585
Use javascript routine below to set and get cookie values

Call setCookie like this via javascript, you will send the value of the fields to this function called initCookie with cookie identifier

In initCookie,
cookiename would be the identifier for the cookie
paravalue would be the actual value
now would define the expiry of cookie


=======================
function initCookie(cookieName, paraValue) {
        var now = new Date();
     // cookie expires in one day
     now.setTime(now.getTime() + 1 * 24 * 60 * 60 * 1000);
     // set the new cookie
     setCookie(cookieName, paraValue, now);
}

function setCookie(name, value, expires, path, domain, secure) {
     var curCookie = name + "=" + value +
         ((expires) ? "; expires=" + expires.toGMTString() : "") +
         ((path) ? "; path=" + path : "") +
         ((domain) ? "; domain=" + domain : "") +
         ((secure) ? "; secure" : "");
     document.cookie = curCookie;
}

function getCookie(name) {
     var dc = document.cookie;
     var prefix = name + "=";
     var begin = dc.indexOf("; " + prefix);
     if (begin == -1) {
       begin = dc.indexOf(prefix);
       if (begin != 0) return null;
     } else
       begin += 2;
     var end = document.cookie.indexOf(";", begin);
     if (end == -1)
       end = dc.length;
     return dc.substring(begin + prefix.length, end);
}


~Hemanth
0
 

Author Comment

by:mfay72
ID: 6479761
Hemanth,

Thank you so much for answering... I think this is exactly what I'm looking for. Just one question: How would I declare paraValue? For example, I would say

function initCookie(userName, paraValue) and you said that paraValue would be the actual value....or do I say function initCookie(cookieName, userName)? I'm confused as to what the actual value actually is.

I'm sorry for my lack of expertise in this...I'm familiar with JavaScript, but new to cookies.

Melanie
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6479976
for eg: if you have a field called user in the login form, then call the function like this.

initCookie( "UserName", document.forms[0].user.value)

Here UserName would be the cookie name and user.value will be cookie value
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:mfay72
ID: 6479997
OK...I think I see....would I call this in the onload event of the form then? Also, would I need to declare var curCookie like this:

var curCookie = name + "=" + document.forms[0].user.value

Melanie
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6480235
No, don't alter the setcookie and getcookie methods, they will just set or read cookie from local machine.

OnUnload event of the form call this function like initCookie( "UserName", document.forms[0].user.value)

which will create username cookie in local machine

In onload event use getCookie to determine if there is a cookie named "UserName" if exists then extract value of the cookie and welcome the user.

Hope it is clear.

0
 

Author Comment

by:mfay72
ID: 6482270
OK...I will try this today, and let you know how it comes out. I got very busy yesterday afternoon, which is why I didn't respond sooner. Thank you again, Hemanth, for all your help in this matter...you're the best!
0
 

Author Comment

by:mfay72
ID: 6487403
Thank you so much, Hemanth! This worked beautifully!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question