Reading a cookie set in javascript with php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Khaiya
    New Member
    • Mar 2007
    • 4

    Reading a cookie set in javascript with php

    I'm trying to read a cookie that I set with javascript with php. I've tried many websites and nothing I've found works at ALL (except var_dump() printed up null) but other then that all I've gotten is a blank page.

    Here is what I've tried...


    (page1.php)
    [code=javascript]
    <script>
    createCookie('n ame','jim',7)


    function createCookie(na me,value,days) {
    if (days) {
    var date = new Date();
    date.setTime(da te.getTime()+(d ays*24*60*60*10 00));
    var expires = "; expires="+date. toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+ expires+"; path=/";
    }
    </script>
    [/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    (page2.php)
    [code=php]
    <?php

    $var1=$_COOKIE['name'];

    echo $var1;


    ?>
    [/code]

    I've also tried...
    [code=php]
    <?php

    $var1=var_dump( $_COOKIE['name']);

    echo $var1;


    ?>
    [/code]
    but so far nothing has happened.
    Last edited by pbmods; May 29 '07, 06:37 PM. Reason: Added code tags.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Originally posted by Khaiya
    [code=php]$var1=var_dump( $_COOKIE['name']);[/code]
    var_dump doesn't return anything. Instead, try this:

    [code=php]
    var_dump($_COOK IE);
    [/code]

    Check to make sure the domain and expiration date for your cookies are valid.

    Comment

    • Khaiya
      New Member
      • Mar 2007
      • 4

      #3
      Originally posted by pbmods
      var_dump doesn't return anything. Instead, try this:

      [code=php]
      var_dump($_COOK IE);
      [/code]

      Check to make sure the domain and expiration date for your cookies are valid.

      I've tried that now and it didn't work either, and I guess the main problem is that I only sort of know the domain and expiration date of my cookies, and I don't really understand what var_dump() even does...

      I know that a cookie automatically attaches the domain that it was saved from to the cookie but when I call the cookie how do I specify the domain name it came from?

      Comment

      Working...