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:
browser request page yourpage.php. first run cookie empty, on server side cookie empty anycase.
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>
browser receiving cookie js
- on next visit php code sees cookie , assign post variable, finishes it's life after page execution.
- if destroy cookie (by uncomment commented line), @ 3rd step browser removes cookie, on 4th stage browser doesn't see cookie :)
Comments
Post a Comment