We help IT Professionals succeed at work.

Finding information on connection...

LSILes asked
Last Modified: 2013-12-25
I know about browscap, and how to get some of the browser information, but I want to know if there is any way to get a user's e-mail address just from being connected to your web site.  If there is not any "generic" or built-in function that can do this, is there a software package that might work?  I'd much rather a built-in function, but I'll give points to anyone who can direct me to a software package (just as long as it is a very good package).  

I know that I could have a user type in there information to logon to the page (or a certain part of it), but I want the ability to pull it up immediately without any prompts.  Reason being, just to build rapport, e.g.  User John Doe connects to your web site, and immediately he gets a nice warm welcome message saying something like, "Welcome back John.  We missed you."  I'm sure that I could do this with cookies, but I'm not sure that's the way I wanna do it.  Is there any other way around this?  Please give me some ideas people.  You'll get the points if you can satisfy the question in the first paragraph (above) or give me an even better way to do this.  Thanks!

Oh, and we're using IIS4 on NT 4.0 just in case you need to know.

Watch Question

The simple answer is that there is no way of getting a users email address just by them connecting to your web site. If it were an intranet then you may have some joy with an ASP/DLL arrangement which could look up their email address in Exchange Server using their network user id, but in general terms you will have to ask the visitor to type in their email address and use a cookie on their machine or store it on your server against their IP address ready for their next connection. (this will be very unreliable for user's who's ISP allocate their IP addresses dynamically at each connection).

Just my 2p's worth....


Hmmm...  well, looks like I'll have to change my question a bit then, eh?  Can someone provide me with sample code on how to do the cookie bit?  I have had a tad of experience with cookies, but not for a while, so...  

Also, with cookies, shouldn't I be able to get the information from their computer (only after they've typed it in the first time) without needing them to type their e-mail address or anything?  I thought you could at least do that, but let me know if I'm wrong.  Thanks for the comments all!  Please continue to feed the hungry fool.

Michel PlungjanIT Expert
Top Expert 2009

A cookie will hold whatever you put in to it (size limitations do apply)
It will be sent to your server with each request for a new page and is available to JavaScript IN the pages on all pages in the path set in the cookie (but only within YOUR domain)

ASP sets session id's in cookies

cgis can set and get cookies

JavaScripts in pages can set and get cookies...

For casual visits you can hold the name and the number of times and the date of last time visited.
For clients/customers you could hold a small token with a key to a database record on your server.



Well, I guess that's as good as it gets.  But, I'll wait until someone gives me some example code (and please make it good) before I fork out the points.  Thanks!

Michel PlungjanIT Expert
Top Expert 2009

I made the comment because you might want to refine the question.

Since this is the Web Authoring section I did not want to lock you into a technique.

Here is one in JavaScript:

<TITLE>Get and set name cookie</title>
<SCRIPT LANGUAGE="JavaScript"><!-- // hide
// Script is a cleaned and modified version of one found at JavaScript World.

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));

function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   return null;

function SetCookie (name, value) {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path    = (argc > 3) ? argv[3] : null;
   var domain  = (argc > 4) ? argv[4] : null;
   var secure  = (argc > 5) ? argv[5] : false;
   // values must be urlencoded (escaped) - some early versions of MSIE 3 does not have escape()??
   document.cookie = name + "=" + escape (value) +
   ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
   ((path == null) ? "" : ("; path=" + path)) +
   ((domain == null) ? "" : ("; domain=" + domain)) +
   ((secure == true) ? "; secure" : "");

<SCRIPT LANGUAGE="JavaScript"><!-- // hide
var username = GetCookie('username');
var BackAgain = '';
if (!username) {
  username = prompt('Please enter your name (otherwise press cancel)',"");
  if (!username) {
    alert('Its ok if you dont want to tell me your name');
    username = 'WebSurfer';
  else {
    // don't set the username cookie.... because the user refused to tell you.
    // they will be prompted next time....
    pathname = location.pathname;
    myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
    // set expiry date to 1 year from now.
    var largeExpDate = new Date ();
    largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000));

else BackAgain = ' back';

document.write('<H3>Welcome'+BackAgain+', '+username+'</H3>');
We have the following on the agenda


From CGI:

Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure


NAME           The name you whish to reference the variable with
VALUE          The value to associate with this variable.
                      NOTE: Cookie Length is limited to 4K
DATE            Is the time at which the cookie information expires and will be
                     "forgotten" by the browser. If it isn't set then the Cookie will be
                     forgotten when the user closes their browser.
                     NOTE: The date needs to be in the following format.
                     'Wednesday, 09-Nov-99 23:12:40 GMT'
DOMAIN        Is a host or domain name for which the cookie is valid.
PATH           Specifies a subset of the URLs at that server for which the cookie
                    is valid (use / for the complete server).
SECURE      If you include "secure" in your cookie, then the cookie will only be
                    transmitted over an SSL connection.

It will be returned to the server as HTTP-COOKIE

Michel PlungjanIT Expert
Top Expert 2009

PS The Set-Cookie in the cgi is of course an HTTP header. It may therefore also be set in the page with
<META HTTP-EQUIV="Set-Cookie" CONTENT="same parameters as cgi">



I'm sorry to deny your answer, but if you read my comment, you'll know why.  Also, I would appreciate it if the person that actually does send me some real code would write it in ASP.  Thanks!



Uh, er.... I feel like a dip$#!*....  I guess I didn't scroll high enough the first time I look at it.  I apologize Michel...  just post an answer again, and you'll get the points.  Sorry, sorry, sorry...

IT Expert
Top Expert 2009
Unlock this solution and get a sample of our free trial.
(No credit card required)


Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.