cookies tutorials?

  • jlknauff
  • Expert
  • Expert
  • User avatar
  • Posts: 502
  • Loc: Florida

Post 3+ Months Ago

can anyone tell me where to find a tutorial on making a cookie with CGI? What I need to do is collect data as a visitor goes through my site and when they are done submit it through sendmail. I can do the last part but can't find how to collect and store the data before it is sent. Thanks in advance guys.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

what data do you want to collect?

A cookie is a piece of information that your server sends to the user and that the user send back on each subsequent page request.

The only way to get a user's information from a cookie is if you already know it and have sent it to the user in a cookie. To do taht you would probably need them to fill in a form of some description.

What language are you using? IF its perl then have a look at the CGI::Cookie module.
  • Managedlinks
  • Proficient
  • Proficient
  • Managedlinks
  • Posts: 294

Post 3+ Months Ago

If I was doing what you asked I would use javascript to store the information in a cookie. I wouldn't use CGI until perhaps the last step i.e. sending the form.

On each page a small script appends the page information to a cookie

When the user is ready to submit the information then another small script ads it to the form which is then sent to the server for mailing or even sent directly using a simple "mailto" action
  • Managedlinks
  • Proficient
  • Proficient
  • Managedlinks
  • Posts: 294

Post 3+ Months Ago

here are a couple of javascript functions to help in setting and getting the cookies

Code: [ Select ]
function GetCookie(sCookie)
{
 // cookies are separated by semicolons
 var aCookie = document.cookie.split("; ");
 for (var i=0; i < aCookie.length; i++)
 {
  // a name/value pair (a crumb) is separated by an equal sign
  var aCrumb = aCookie[i].split("=");
  if (sCookie == aCrumb[0] && aCrumb[1])
     return unescape(aCrumb[1]);
 }
 // a cookie with the requested name does not exist
 return null;
}


function SetCookie(data)
{
 cookie = GetCookie('cookiename'); // get existing cookie
 oldcookie = '';
 if (cookie)    
 {
  oldcookie = cookie + '||'; // add old cookie and a seperator
 }

 // set the cookie adding the new data
 document.cookie = 'cookiename=' + oldcookie + data;
}
  1. function GetCookie(sCookie)
  2. {
  3.  // cookies are separated by semicolons
  4.  var aCookie = document.cookie.split("; ");
  5.  for (var i=0; i < aCookie.length; i++)
  6.  {
  7.   // a name/value pair (a crumb) is separated by an equal sign
  8.   var aCrumb = aCookie[i].split("=");
  9.   if (sCookie == aCrumb[0] && aCrumb[1])
  10.      return unescape(aCrumb[1]);
  11.  }
  12.  // a cookie with the requested name does not exist
  13.  return null;
  14. }
  15. function SetCookie(data)
  16. {
  17.  cookie = GetCookie('cookiename'); // get existing cookie
  18.  oldcookie = '';
  19.  if (cookie)    
  20.  {
  21.   oldcookie = cookie + '||'; // add old cookie and a seperator
  22.  }
  23.  // set the cookie adding the new data
  24.  document.cookie = 'cookiename=' + oldcookie + data;
  25. }

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 83 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.