PDA

View Full Version : Once a day access



Soren Twilight
06-02-2006, 02:15 AM
Does anyone know a script in which a user can veiw a page one a day and if the user veiws it once more the text will change?

Soren Twilight
06-02-2006, 02:17 AM
For example: the page has a link that reads 'continue'. If the user veiws the page more than once on the same day, the text will change and say "Sorry you have already veiwed this page today, please return tomorrow."

tech_support
06-02-2006, 02:42 AM
Think you need to use cookies for that...

See if you can modify this script:

http://www.javascriptkit.com/script/script2/visitorinfo.shtml

Soren Twilight
06-02-2006, 02:45 AM
I'm not very good at editing scripts.... but thank you. Is there another possibility anyone?

Twey
06-02-2006, 02:52 AM
There's nothing secure you can implement here. Even with a server-side script, you'd need to set up a login system and do it by that.

tech_support
06-02-2006, 03:35 AM
I think this will work... (Haven't tried it!)

Put it in the <BODY> tags.


<SCRIPT LANGUAGE="JavaScript">

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)
break;
}
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;
visit++;
SetCookie("visit", visit, expdate, "/", null, false);
var message;
if(visit == 1)
alert("Welcome!")
if(visit>= 2)
alert("You've been here too many times. Try again tommorrow.")
//TO REDIRECT, DELETE THE "//" UNDER
//window.location = "mypage.htm"

//TO NOT CLOSE, DELETE THE NEXT TWO LINES UNDER
window.opener = self
window.close()
}
function ResetCounts() {
var expdate = new Date();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
visit = 0;
SetCookie("visit", visit, expdate , "/", null, false);
history.go(0);
}

window.onload=DisplayInfo
</Script>

benslayton
06-02-2006, 03:59 AM
:mad: That closes my browsers out...:mad:

benslayton
06-02-2006, 04:05 AM
I dont know but this is a second start:

<html>
<head>
<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"
}
}
</script>
</head>
<body>
<div align="center"><a href="#" onclick=" ConfirmChoice(); return false;">Try this!!! </a> </div>
</body>
</html>
HeHe!!

djr33
06-02-2006, 04:31 AM
Cookies are the only way without logins or some one-time-use security code or something.

However, the user can clear cookies.

Actually, though, there is a better way now that I think about it... use IP address.

In php, it's fairly easy... but you'd need to have serverside access. That's how you'd need to store the "used" IPs.


Now... note... there are obvious flaws with this... if someone refreshed, for example. but... do what you want.

Twey
06-02-2006, 04:32 AM
benslayton: What the heck is that code? :-\
window.alert() doesn't return a value.

djr33
06-02-2006, 04:36 AM
I don't get the second one either. Seems dependant on clicking a link... hitting refresh would load just fine twice, or more.

benslayton
06-02-2006, 04:51 AM
um well, it works in my browser.

tech_support
06-02-2006, 04:58 AM
:mad: That closes my browsers out...:mad:
What do you want it to do?

benslayton
06-02-2006, 05:01 AM
Well I figured it would be better if it redirects to his home page/index.

tech_support
06-02-2006, 06:21 AM
Try this: (Just be careful! This counts how many times you visit the page!)


<SCRIPT LANGUAGE="JavaScript">

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)
break;
}
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;
visit++;
SetCookie("visit", visit, expdate, "/", null, false);
var message;
if(visit == 1)
alert("Welcome!")
if(visit>= 2)
alert("You've been here too many times. Try again tommorrow.")
window.location="about:home"

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

window.onload=DisplayInfo
</Script>

benslayton
06-02-2006, 02:11 PM
here is what i found

<? //start your PHP!

if (!$_COOKIE['visited']) { //Let's check if the cookie isn't set

setcookie("visited", "true"); //The cookie wasn't set so let's set it now!

echo "You may visit this page only one time a day."; //Tell the user!
}

else {
echo "Sorry but you have already visited this page, try back tomorrow"; //Tell the user!
}

?>

Soren Twilight
06-02-2006, 09:03 PM
Thanks for all the suggestions you guys :)
any more ideas are welcome