/    Sign up×
Community /Pin to ProfileBookmark

Looking for help with a script to control access to parts of my site

Hello, newbie here ? I did a search and either don’t know how to phrase what I’m looking for properly or just can’t find it, I’m not sure which.

I have a website that sells books. There is a page on each book with links to an excerpt. All of the excerpts are image files in one subdirectory, entitled “fiction.” The first time a visitor clicks on the excerpt link, I want them to be taken to a “terms and conditions” page to which they must agree before they can view the excerpt.

I have a code that works fine, they mark the checkbox and the submit button allows them to move to the next page. However, what I’m looking for is something a little more robust that will do two things:

1) create a cookie on the visitor’s computer so that if they view one excerpt, then visit another page OUTSIDE of the “fiction” directory (say, another book) and then re-enter the directory to view a different excerpt, then they are not prompted to agree to the terms again; and

2) once they’ve agreed to the terms and checked the box, then they will be redirected to the appropriate excerpt based upon where they came from.

My question then is simply, can this be done? Though I can code when I need it, I can’t seem to get anything to work right for me on this. Any help or direction would be greatly appreciated.

Thanks for reading this ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@steelersfan88Aug 25.2004 — PHP will work just as you need it. It can work cookies and do redirection, and it accessible to all browsers, unlike JS.
Copy linkTweet thisAlerts:
@jherusalemauthorAug 25.2004 — Unfortunately I don't know PHP. A co-worker of mine wrote a script in ASP that would work, but my server doesn't support that.

Thanks though!
Copy linkTweet thisAlerts:
@emblemAug 26.2004 — try [COLOR=skyblue]t[/COLOR] [COLOR=royalblue]h[/COLOR] [COLOR=blue]i[/COLOR] [COLOR=darkblue]s[/COLOR] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
pp = "www.your-path-to/the/protected/page.html"
var agree = GetCookie("agree")
if(agree == "1") {
location.href = pp;
}
else if(agree == "0") {
var chance = confirm("You said you did not agree before.nBut im nice and i will give you another chance.nnOK?")
if(chance) {
DeleteCookie("agree")
}
else {
alert("Have it your way");
hystory.go(-1)
}
}
function ckbx(f) {
var checked = f.checked;
}
function checkCheckBox(){
if (checked)
{
alert('You dont agree.n then I will have to send you back!');
SetCookie("agree","0")
history.go(-1)
}else
SetCookie("agree","1")
location.href = pp;
}
function getCookieVal (offset) { <br/>
var endstr = document.cookie.indexOf (";", offset); <br/>
if (endstr == -1) <br/>
endstr = document.cookie.length; <br/>
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) { <br/>
var arg = name + "="; <br/>
var alen = arg.length; <br/>
var clen = document.cookie.length; <br/>
var i = 0; <br/>
while (i &lt; clen) { <br/>
var j = i + alen; <br/>
if (document.cookie.substring(i, j) == arg) <br/>
return getCookieVal (j); <br/>
i = document.cookie.indexOf(" ", i) + 1; <br/>
if (i == 0) break; <br/>
} <br/>
return null;
}
function SetCookie (name, value) { <br/>
var argv = SetCookie.arguments; <br/>
var argc = SetCookie.arguments.length; <br/>
var expires = (argc &gt; 2) ? argv[2] : null; <br/>
var path = (argc &gt; 3) ? argv[3] : null; <br/>
var domain = (argc &gt; 4) ? argv[4] : null; <br/>
var secure = (argc &gt; 5) ? argv[5] : false; <br/>
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) + <br/>
((domain == null) ? "" : ("; domain=" + domain)) + <br/>
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) { <br/>
var exp = new Date(); <br/>
exp.setTime (exp.getTime() - 1); <br/>
var cval = GetCookie (name); <br/>
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
// End --&gt;
&lt;/script&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;form onsubmit="checkCheckBox(this)"&gt;
I agree: &lt;input type="checkbox" value="0" name="agree" onclick="ckbx(this)"&gt;
&lt;input type="submit" value="Continue"&gt;
&lt;input type="button" value="Exit" onclick="history.go(-1)"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @jherusalem spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...