View Full Version : Once a day access script problem

06-03-2006, 04:49 PM
I wanted a script where the user veiws the page once and might see a link that says, "Continue". But the second time the user veiws the page, the text will change to something like, "Sorry you may only access this page once per day. Please return tommorow." The next day the text will reset and read, "continue" again.

I went to another forum and asked the same questions and helpfully they returned a few scripts.

The first of which will work in my situation quite fine although it isn't exactly what I wanted. In this script, you press the link 'Try this' for the first time and an alert box pops up and says, "Sorry, but you can only visit this page once a day. Try again tomorrow." and that's what it always has done.
Here it is:

<title>Demo Box</title>
<script language="javascript">
function ConfirmChoice()
answer = alert("Sorry, but you can only visit this page once a day. Try again tomorrow.")
if (answer !=0)
location = "index.html"
<div align="center"><a href="#" onclick=" ConfirmChoice(); return false;">Try this!!! </a> </div>

The second of the scripts I do not have the knowledge or ability to describe in detail the problems, although I do know that it does not work.... but maybe you know more about how it works and what the problem is. Usually, when I insert the correct pages into the script, it always goes to the page that the user is only supposed to see once a day.
Here it is:


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)
return null;
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? 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 DisplayInfo() {
var expdate = new Date();
var visit;
expdate.setTime(expdate.getTime() + (24));
if(!(visit = GetCookie("visit")))
visit = 0;
SetCookie("visit", visit, expdate, "/", null, false);
var message;
if(visit == 1)
if(visit>= 2)
alert("You've been here too many times. Try again tommorrow.")

function ResetCounts() {
var expdate = new Date();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
visit = 0;
SetCookie("visit", visit, expdate , "/", null, false);


Please keep in mind that I am the very most basic kind of begineer there is to Javascripts (I only got Javascript for dummies yesturday) so I can't edit these scripts myself (thus my post, here at CodingFurums).

Let's say to keep things organized, we will refer to the too existing problem scripts as script 1 and script 2.

Also, because of the way my page is set up, users will not be able to refresh the page that the once a day access script will be on.

Furthermore, any completely new scripts and script ideas are completely welcome. :D

Thanks in advance!

06-03-2006, 05:32 PM
Here is an idea: forget about that whole concept (though I'm curious what type of information your visitors can view only once a day).
The easiest implementation is to use cookies to track visitors, that is what the second script you posted does. However I can easily clear cookies or disallow web site setting them in the first place.
You could have a server side database and track user IP address and last access time, but then there are dynamic IP addresses and proxies.

In any event, my point is that you can not reliably accomlish what you are trying to do.

06-03-2006, 05:44 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"



<body onload="f19_GetFormCookie();">

<script language="JavaScript" type="text/javascript">
// Form Compendium f19_Part2 (12-05-2005)
// Form Cookie
// by Vic Phillips http://www.vicsJavaScripts.org.uk

var f19_Days=2; // The cookie will be available on revisits for a specified number of days
var f19_Cookie='My Form'; // The Cookie name

var zxcToDay=new Date();

// Functional Code

// No Need To Change ***************************

var f19_Exp=new Date(new Date().getTime()+f19_Days*86400000).toGMTString();

function f19_GetFormCookie(){
zxcCodeDate=(zxcToDay.getFullYear()+'')+(zxcFormatNu(zxcToDay.getMonth())+'')+(zxcFormatNu(zxcToDay. getDate())+'');
if (f19_TBString){
if (zxcCodeDate<=f19_TBString){
alert('Go Away');

function f19_GetCookie(name) {
var f19_st=document.cookie.indexOf(name+"=");
var f19_len=f19_st+name.length+1;
if ((!f19_st)&&(name != document.cookie.substring(0,name.length))) return null;
if (f19_st==-1) return null;
var f19_end=document.cookie.indexOf(";",f19_len);
if (f19_end==-1) f19_end=document.cookie.length;
return decodeURI(document.cookie.substring(f19_len,f19_end));

function f19_SetFormCookie(value){

function zxcFormatNu(zxcnu){
if (zxcnu<10){ zxcnu='0'+zxcnu; }
return zxcnu;



06-03-2006, 06:14 PM
That's good, but is there a way so that when the 'Go away' alert box pops up, after the user clicks ok, he/she are redirected to another page?

06-03-2006, 06:59 PM
Nevermind! Thanks so much! Thats just what i needed!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum