PHP/JavaScript cookie acting like a pointer so when I clear it, I lose the value; how do I grab the value from the cookie? -


<script type="text/javascript">     var test = "test";     document.cookie = "some_test=" + guid; </script>  <?php $_post['important_value'] = ((isset($_cookie['some_test'])) ? ($_cookie['some_test']) : ('')); ?>  <script>     //document.cookie = "some_test=;expires=thu, 01 jan 1970 00:00:00 utc;";     console.log(document.cookie); </script> 

this code works intended long don't uncomment line clear cookie. goal move javascript variable (test) php variable ($_post['important_value']).

i think what's happening $_post['important_value'] , $_cookie['some_test'] pointing same thing wrong. there anyway print address of variables?

update:

debug_zval_dump($_post['important_value']); // string(39) "750118664537365903071115537365768136624" refcount(3)  debug_zval_dump($_cookie['some_test']); // string(39) "750118664537365903071115537365768136624" refcount(3)  

i'm assuming means assumption correct? how string value cookie without pointer?

let's understand how code works:

  1. browser request page yourpage.php. first run cookie empty, on server side cookie empty anycase.

  2. browser loads page js, first run equals:

    <script type="text/javascript">   var test = "test";   document.cookie = "some_test=" + guid; </script>  <script>     //document.cookie = "some_test=;expires=thu, 01 jan 1970 00:00:00 utc;";     console.log(document.cookie); </script> 
  3. browser receiving cookie js

  4. on next visit php code sees cookie , assign post variable, finishes it's life after page execution.
  5. if destroy cookie (by uncomment commented line), @ 3rd step browser removes cookie, on 4th stage browser doesn't see cookie :)

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -