Custom Search
www.rocket99.com : Technical Guides Sybase Oracle UNIX Javascript


Technical Guides
Sybase
Oracle
UNIX
Javascript




Of Interest

Business Intelligence and Analytics



Oracle Training





Javascript » Methods » Coding »

Accessing the cookie file

     



For Netscape users, there is a file in the c:\netscape directory called cookies.txt.
Explorer uses a directory to store this data, in c:\winnnt\cookies or c:\windows\cookies.
Many web pages use this file to store information to store session variables,
or to determine if a user is new to a web site.





The file is handled similar to the way an INI file is accessed,
except that cookie data has an "expiration date".



All operations to the cookies file are not written to the hard disk until the browser is closed. This is transparent to any functions that use the cookies file.

Each element in the file has a keyword, expiration date, and value. To set a value in the file, a very specific format is needed. Getting a value from this file involves parsing out each line until the desired element is found.

A set of functions is available for accessing the cookies file.

f_setcookie(keyword,value,exp_date)

Sets a value in the cookies file for the lable specified. Null can be used in place of the expiration date if the access is session-specific.
Example: f_setcookie("username","jake",null);

f_getcookie(keyword)

Returns the value from the cookies file for the value specified.
Example: cur_name = f_getcookie("username");

Here is the source code for the functions:

 function f_getcookieval(offset) {
         var endstr = document.cookie.indexOf (";", offset);
         if (endstr == -1) endstr = document.cookie.length;
         return unescape(document.cookie.substring(offset, endstr));
 }
 
 function f_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 f_getcookieval (j);
                 i = document.cookie.indexOf(" ", i) + 1;
                 if (i == 0) break;
         }
         return null;
 }
 
 function f_setcookie (name, value, expires) {
         document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
 }
 
 






Javascript : Related Topics

Javascript : Methods : Incrementing a counter within an edit field
Javascript : Methods : Animation Example
Javascript : Methods : Image Mapping Example
Javascript : Methods : Redirecting Page Access
Javascript : Methods : Loading a new page dynamically
Javascript : Methods : Complex Application with Forms
Javascript : Methods : Image Viewer with Prev and Next Buttons
Javascript : Methods : Array Processing, Frameset Writes
Javascript : Methods : Javascript: Where it fits in HTML
Javascript : Methods : Using include files
Javascript : Methods : Pure virtual call error
Javascript : Methods : Passing variables to windows
Javascript : Methods : Executing Dynamic Code
Javascript : Methods : Single line edit: Data entry issue
Javascript : Methods : Call CGI counter
Javascript : Methods : Dynamic Objects and Names
Javascript : Methods : Setting Focus to a Control During Load

Sybase Web Site
Sybase iAnywhere Mobile Web Site
Oracle Enterprise Web Site



Get the latest Rocket99 news and tech tips via






Site Index About this Guide to Sybase, Oracle, and UNIX Contact Us Advertise on this site




Copyright © 2016 Stoltenbar Inc All Rights Reserved.