read cookie with php after its generated with JS

Discussion in 'PHP' started by karabunda, Jul 16, 2009.

  1. #1
    Hi

    I'm not real good with coding, so here goes:

    I have two scripts at end of page, one after the other:

    <script src="http://mysite.com/script1.php" type="text/javascript"></script>

    <img src="http://mysite.com/script2.php" style="width:1px; height:1px;">

    The first one creates some unique ID, and posts it in cookie of user.

    The second one waits for 2 seconds, then reads the ID from the cookie and inserts it into a table.

    However all the IDs that go into the table are 0 (meaning that when the second script accesses the cookie, it gets null).

    Anyone has an idea why is it happening?

    Thanks.
     
    karabunda, Jul 16, 2009 IP
  2. funzie

    funzie Well-Known Member

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    123
    #2
    Are you sure the cookie is being written to the browser? Look for it and read the data. How are you reading the cookie? Without any code on how you are doing it, it's really hard to help you. I can't read minds yet. Lol.
     
    funzie, Jul 16, 2009 IP
  3. credobyte

    credobyte Peon

    Messages:
    38
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Show us what you are doing ( scripts ) and maybe someone will help you.
     
    credobyte, Jul 16, 2009 IP
  4. vpdesigns

    vpdesigns Peon

    Messages:
    353
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    We would need to see the first script which generates the cookie.
     
    vpdesigns, Jul 17, 2009 IP
  5. mioot

    mioot Peon

    Messages:
    169
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you creating a cookie using php means. The cookie cannot get read in that page itself. U need to navigate to another page than only u can read that cookie using php.
    (or)
    If you creating a cookie using javascript "document.cookie = " means. You can access that cookie within that page itself using document.cookie.

    to check Ur cookie is added in that page after add your cookie. Put alert(document.cookie);
     
    mioot, Jul 17, 2009 IP