Solved

Cookie help needed on user recognition

Posted on 2001-09-13
7
200 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 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:mfay72
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you so much, Hemanth! This worked beautifully!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now