Javascript & Cookie based Visitor Application

CK1820 
Created at Aug 28, 2007 23:24:00 
102   0   0   0  
This cookies records how many times the visitor has visited the page and writes to the page accordingly.

visits.js
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;
  document.cookie = name   "="   escape (value) 
  ((expires == null) ? "" : ("; expires="   expires.toGMTString())) 
  ((path == null) ? "" : ("; path="   path)) 
  ((domain == null) ? "" : ("; domain="   domain)) 
  ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name   "="   cval   "; expires="   exp.toGMTString();
}

var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime()   (expDays*24*60*60*1000));

function amt(){
  var count = GetCookie('count')
  if(count == null) {
    SetCookie('count','1')
    return 1
    }
    else {
    var newcount = parseInt(count)   1;
    DeleteCookie('count')
    SetCookie('count',newcount,exp)
    return count
  }
}

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

function printOut() {
  document.write("You've been here <b>"   amt()   "</b> times.");
}

visitor_test.html
<html>
<head>
  <title>KURAPA.COM Visitor Test</title>
  <script type="text/javascript" src="visits.js"></script>
</head>

<body>
<script type="text/javascript">
<!--
  printOut()
//-->
</script>



Tags: Cookie GetCookie HTML Javascript SetCookie Visitor setTime unescape Share on Facebook Share on X

◀ PREVIOUS
Cross Browser Event Management Functions Using JavaScript
▶ NEXT
How to record visitor's name by Cookie
  Comments 0
Login for comment
SIMILAR POSTS

Cross Browser Event Management Functions Using JavaScript (created at Aug 28, 2007)

How to record visitor's name by Cookie (created at Aug 28, 2007)

Save And Restore Form Cookies in Javascript (created at Aug 29, 2007)

Let popup once for event dialog or something like that in Javascript (created at Aug 29, 2007)

New content notifier in Javascript (created at Aug 29, 2007)

Cookie Redirect (created at Aug 29, 2007)

Cookie enabled browser checking in Javascript (created at Aug 29, 2007)

Access Granted (created at Aug 29, 2007)

Greeting For The Time Of Day (created at Aug 29, 2007)

Displays the number of pages that the users browser has displayed in its session (created at Aug 29, 2007)

Address Book (created at Aug 29, 2007)

Basic Date Display (created at Aug 30, 2007)

Javascript implemented Calendar (created at Aug 30, 2007)

Javascript based Alarm Clock (created at Aug 30, 2007)

How to get date time in Javascript ? (created at Aug 30, 2007)

Hiding HTML on the browser (created at Aug 30, 2007)

Getting WebSearchers On Your Site (created at Aug 30, 2007)

Javascript Mouse Event Handler Example (created at Aug 30, 2007)

Select And Deselect All Checkboxes By Javascript (created at Aug 30, 2007)

How To Read And Write A Cookie (created at Aug 26, 2007)

Using C# With Cookies (created at Aug 26, 2007)

Printing A Page (created at Aug 26, 2007)

Example Of Creating Objects (created at Aug 26, 2007)

Linking Drop Downs (created at Aug 26, 2007)

Roman Numerals From Integers (created at Aug 26, 2007)

Get A Print Dialog Box By Clicking A Button (created at Aug 26, 2007)

Keyboard event detection (Key Tracker) (created at Aug 26, 2007)

IsIn For Arrays (created at Aug 26, 2007)

Confirm The Link Clicked (updated at Jan 15, 2024)

Enlarge Image (created at Sep 03, 2007)

OTHER POSTS IN THE SAME CATEGORY

JQuery And Function Chaining (created at Aug 30, 2007)

How to get date time in Javascript ? (created at Aug 30, 2007)

Javascript based Alarm Clock (created at Aug 30, 2007)

Javascript implemented Calendar (created at Aug 30, 2007)

Basic Date Display (created at Aug 30, 2007)

Address Book (created at Aug 29, 2007)

Displays the number of pages that the users browser has displayed in its session (created at Aug 29, 2007)

Greeting For The Time Of Day (created at Aug 29, 2007)

Access Granted (created at Aug 29, 2007)

Cookie enabled browser checking in Javascript (created at Aug 29, 2007)

Cookie Redirect (created at Aug 29, 2007)

New content notifier in Javascript (created at Aug 29, 2007)

Let popup once for event dialog or something like that in Javascript (created at Aug 29, 2007)

Save And Restore Form Cookies in Javascript (created at Aug 29, 2007)

How to record visitor's name by Cookie (created at Aug 28, 2007)

Cross Browser Event Management Functions Using JavaScript (created at Aug 28, 2007)

Printing A Page (created at Aug 26, 2007)

Example Of Creating Objects (created at Aug 26, 2007)

Linking Drop Downs (created at Aug 26, 2007)

Roman Numerals From Integers (created at Aug 26, 2007)

Get A Print Dialog Box By Clicking A Button (created at Aug 26, 2007)

Keyboard event detection (Key Tracker) (created at Aug 26, 2007)

IsIn For Arrays (created at Aug 26, 2007)

UPDATES

Creating a Pinterest-Style Card Layout with Bootstrap and Masonry (created at Apr 24, 2024)

Mastering Excel Data Importation in PHP (updated at Apr 24, 2024)

JSON format control in PHP (updated at Apr 24, 2024)

Equal Height Blocks in Bootstrap with JavaScript (created at Apr 22, 2024)

How to convert integer to text string ? (updated at Apr 22, 2024)

Checking similarity between two strings in PHP (updated at Apr 21, 2024)

Create Blob Image in HTML based on the given Text, Width and Height in the Center of the Image without saving file (updated at Apr 21, 2024)

How do I determine the client IP type (IPv4/IPv6) in PHP (updated at Apr 16, 2024)

How do I determine the client IP type in Python - IPv4 or IPv6 (updated at Apr 13, 2024)

Getting Started with PyTorch: A Beginner's Guide to Building Your First Neural Network (updated at Apr 09, 2024)

Predicting Buyer Preferences with PyTorch: A Deep Learning Approach (updated at Apr 09, 2024)

Forecasting the Weather with PyTorch: A Beginner's Guide to Temperature Prediction (created at Apr 09, 2024)

PyTorch example to Forcast Stock Price based on 10 days Dataset (created at Apr 09, 2024)

Mastering Model Persistence: Saving and Loading Trained Machine Learning Models in Python (created at Apr 08, 2024)

Harnessing the Power of Random Forest Algorithm in Python (created at Apr 08, 2024)

Understanding and Implementing K-Nearest Neighbors (KNN) Algorithm in Python (created at Apr 08, 2024)

Forecasting with Linear Regression and KNN Regression in Python (updated at Apr 07, 2024)

What is 302 Found Redirection in HTTP 1.1? (created at Apr 04, 2024)

Mastering Random Forest Regression: A Comprehensive Guide with Python Examples (updated at Apr 01, 2024)

Python Implementation of Linear Regression (updated at Apr 01, 2024)

Mastering Supervised Machine Learning with Python: A Comprehensive Guide (created at Apr 01, 2024)

Mastering AI: A Beginner's Guide to Python Programming and Beyond (created at Apr 01, 2024)

How do I create animated background for Google Meet? (updated at Mar 28, 2024)

Building a Simple DNS Server in Delphi with TTL Support (created at Mar 16, 2024)

How to force cookies, disable php sessid in URL ? (updated at Mar 16, 2024)

Implementing a Versatile DNS Server in PHP: Handling A, AAAA, CNAME, and TXT Records (updated at Mar 16, 2024)

Implementing a Versatile DNS Server in Python: Handling A, AAAA, CNAME, and TXT Records (created at Mar 16, 2024)

Building a Basic DNS Server in PHP/Python: A Beginner's Guide (updated at Mar 15, 2024)

Dynamic DNS Made Easy: Building a Python-Based Solution (created at Mar 15, 2024)

Exploring the Depths of Data Transfer: sendfile vs. kTLS (created at Mar 15, 2024)