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

Thread: Cookies - The Random 14?

  1. #1
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Post Cookies - The Random 14?

    I need to know how to generate a user number. For example, when a user visits a certain page on my site, they see a 14- or 10-digit (depending on the page) number with any sequence of the following 9 characters: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. I would prefer random against incrementing (for example, 7291862947, 5629857392... instad of 0000000001, 0000000002...). I could do this, but here comes the catch.
    If a user visits the page, they see the number. But then if the user visits the page again 784 days later, it has the same number. Note that 784 days is just an example, it would also have the same number 4, 334 or 2,896 days later. And, a different user has a different number.

    If anyone knows how to do this, please tell me right away.

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

    Default

    You can't, past the time the browser keeps cookies. If the browser keeps cookies forever, that's fine: just generate it and store it in a cookie. Otherwise, however, there's no way to store it forever short of a user account system and server-side code.
    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!

  3. #3
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    OK, I suppose: to keep the cookie the longest possible regarding the configuration.

    Edit: Yay! This is my 100th post!

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

    Default

    As I said, just generate it and store it in a cookie, and don't set an expiry date.
    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
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    How do I make a cookie?
    Last edited by tech_support; 04-11-2007 at 02:38 AM. Reason: Use one question mark please.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

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

    Default

    In Javascript, all cookie data is stored in a string, document.cookie. You can use it just like any other string, except that it persists across page visits.
    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!

  7. #7
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Can you create/read/destroy a JS cookie with php?
    (and vice versa?)
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    To my understanding, yes. I have done this in several scripts (while I was just playing around). Due to the fact that the cookie gets stored in the browser (using both PHP and JS), both can read/edit/delete these cookies (as long as you have the cookie name.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    I know this thread is 4 months old, but I still haven't been able to make a cookie...

    Sorry, mods.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  10. #10
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Cookies are slightly weird I think. Theres some special format. Its like
    name=value;expiredate=aGMTstring;path=generaly/;
    something like that. You have to read and write though. Google it. That'll give you stuff.

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
  •