Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Greeting visitors on website

Posted on 2006-06-26
7
Medium Priority
?
483 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
6 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
Industry Leaders: 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!

 
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 500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

783 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