Passing variable from PHP to Javascript via cookie: How?

Discussion in 'PHP' started by vnviews, Aug 27, 2006.

  1. #1
    I'm trying pass a value from PHP to cookie, then pick up by javascript. But when using setcookie() function in PHP, data is always encoded by urlencode function. So when picking up by javascript I get encoded value. Function escape and unescape in Java seem not to be same as urlencode and urldecode in PHP so I can't decode it.
    How to do? please help me.
    Note that my PHP doesn't support setrawcokie.
    Thanks for your input.
     
    vnviews, Aug 27, 2006 IP
  2. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #2
    Why not just set the variable in 1 or the other and pass the reference back and forth as needed??

    IE if you want to set it through javascript, set it and modify it through javascript. If you need PHP to read the variable, pass it through the query string.
     
    drewbe121212, Aug 27, 2006 IP
  3. hiredgunz

    hiredgunz Peon

    Messages:
    203
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This might also help:

    w3schools.com/js/js_cookies.asp

    best,

    Jan
     
    hiredgunz, Aug 28, 2006 IP
  4. vnviews

    vnviews Peon

    Messages:
    746
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I finally found JS functions that compatible to php urlencode, urldecode.
    Thanks guys.
     
    vnviews, Aug 29, 2006 IP
  5. hiredgunz

    hiredgunz Peon

    Messages:
    203
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Oh cool :) Glad to hear that!

    best,

    Jan
     
    hiredgunz, Aug 29, 2006 IP