Solved

Greeting visitors on website

Posted on 2006-06-26
7
464 Views
Last Modified: 2008-01-09
Hello,
I want to greet visitors on the homepage of my website. welcoming new and identify existing customers. We have separate page for user registration.
How shall I go about?
0
Comment
Question by:soniya
7 Comments
 
LVL 7

Expert Comment

by:ljubiccica
ID: 16983840
You can identify users that already visited your site with cookies...

Once they registrate you make a cookie with their name and once they come back you look tof this cookie...

Than somewhere at the top of your page you write...

//for those who don't have a cookie
Hello and welcome! If you are registered user, you can sign in here...
If not registered, you can register here...

//those with cookies
Wellcome again, Andrew Long. ....

You need a code for that or just the idea???

Ljubiccica
0
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 16984208
Or you do a double, Ip and cookie.

Some people dont allow cookies and some people have changing Ip's
0
 
LVL 6

Expert Comment

by:LeeHenry
ID: 16985374
Have you written the user registration page yet?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Author Comment

by:soniya
ID: 16985714
Yes the User registration form is done.
Can you help me with the code ?
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 125 total points
ID: 17041812
save this as cookie.js

// --- start of cookie.js file
if (!window.daysToKeep) daysToKeep = 365; // default cookie life...
today      = new Date();
expiryDate = new Date(today.getTime() + (daysToKeep * 86400000));

/* Cookie functions originally by Bill Dortsch */

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

function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search)
      if (offset != -1) { // if cookie exists
         offset += search.length
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset)
         // set index of end of cookie value
         if (end == -1) end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      }
   }
}
function delCookie(name,path,domain) {
   if (getCookie(name)) document.cookie = name + "=" +
      ((path)   ? ";path="   + path   : "") +
      ((domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}
// -- end of cookie.js
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17041850
Then in user reg page have

<html>
<head>
<script type="text/javascript" language="JavaScript" src="cookie.js"></script>
<script type="text/javascript" language="JavaScript">
function saveName(theForm) {
  setCookie('name','theForm.firstName.value+' '+theForm.lastName.value,expiryDate,'/')
}
</script>
</head>
<body>
<form onSubmit="saveName(this)">
First name: <input type="text" name="firstName" value="">
Last name: <input type="text" name="lastName" value="">
.
.
.
</form>


and in welcome have

<html>
<head>
<script type="text/javascript" language="JavaScript" src="cookie.js"></script>
<script type="text/javascript" language="JavaScript">
function getName() {
  var name="getCookie('name')
  return (name)?name:'Stranger';
}
</script>
</head>
<body>

<script>
document.write('Hello '+getName())
</script>


0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 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

17 Experts available now in Live!

Get 1:1 Help Now