Solved

Greeting visitors on website

Posted on 2006-06-26
7
471 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

808 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