Results 1 to 6 of 6

Thread: cookies

  1. #1
    Join Date
    Oct 2006
    Location
    미네소타, 미국
    Posts
    158
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default cookies

    can anyone help me to do cookies/content of cookies??

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,625
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You can't create or retrieve a cookie using HTML only. You need to use either a client-side scripting tool like JavaScript or a server-side tool like ASP, PHP, etc.

    If you specify more details about your objective we might be able to help you

  3. #3
    Join Date
    Oct 2006
    Location
    미네소타, 미국
    Posts
    158
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    i just need a cookie that counts how many times they have been to my site
    i should just post in the javascript for this proplem right
    Last edited by lainlives; 10-27-2006 at 04:44 PM.
    The only person I think is cool is -==INSERT YOUR NAME HERE==-

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

    Default

    No, now you've started the thread here we'll carry on. ddadmin will probably move it in a bit. Cookies in Javascript are very simple: they're stored in document.cookie.
    Code:
    <script type="text/javascript">
      var t;
      if(!isNaN(t = parseInt(document.cookie)))
        t = 0;
      document.write("You've visited my site " + t + " times.");
    </script>
    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!

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,625
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    But you can't rely fully on a cookie that work in client-side script as there might be users who have turned off their Javascript in their browsers.

    To overcome that you can develop a cookie using a server side script like ASP or PHP.

    Most importantly you can't keep valuable information in a cookie as the user can remove the cookie at any time they wish.

    If you specify your server side script tool i'll be able to provide the code for using the cookie then

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

    Default

    Remember, users frequently clear their cookies, so it won't be accurate for long periods of time.

    Also, you may want a delay on each "visit" so that you don't count refreshes, viewing multiple pages, etc. as a new visit.


    You could also look into PHP and store in a database by IP address, but since IPs change periodically and some users even share an IP (at different times), that wouldn't be perfectly accurate either.


    It's a hard thing to do.
    The only close-to-foolproof way would be to use a login system, and store based on that username.


    But.... to keep things simple (though not perfect), I'd say a javascript method (like Twey's above) is probably the best answer.
    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

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
  •