?
Solved

Cookie help needed on user recognition

Posted on 2001-09-13
7
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 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