Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Once a day access

  1. #1
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Once a day access

    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?

  2. #2
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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."

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Think you need to use cookies for that...

    See if you can modify this script:

    http://www.javascriptkit.com/script/...itorinfo.shtml
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #4
    Join Date
    Jul 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm not very good at editing scripts.... but thank you. Is there another possibility anyone?

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    I think this will work... (Haven't tried it!)

    Put it in the <BODY> tags.
    Code:
    <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>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  7. #7
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    That closes my browsers out...

  8. #8
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    I dont know but this is a second start:
    Code:
    <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!!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    benslayton: What the heck is that code? :-\
    window.alert() doesn't return a value.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •