javascript - How to read jquery cookie value in php cookie value? -


i not sure possible read jquery cookie value in php cookie value?

var current = $.cookie("count");      show<?php echo $keys; ?><?php setcookie("bgx","document.write(current)");  echo $_cookie["bgx"]; ?>now.play();       $.cookie('count', <?php echo $count; ?>); 

here simple demo shows how create cookie javascript , read php when reload page (because javascript executed after php, client-side). copy code onto new php document, upload server, , try it.

<!doctype html> <html> <head>     <meta charset="utf-8">     <title>demo</title> </head> <body>      <h1>cookie demo</h1>      <p>this demo shows how can create cookie javascript (using jquery), , read php.</p>      <?php          /* portion executed on server */          // if cookie "mycookie" set         if(isset($_cookie['mycookie'])){             echo "<p><b>php found value <i>mycookie</i>: " .  $_cookie['mycookie'] . "</b></p>";         }         else{             echo "<p><b>php did not find value <i>mycookie</i>. give value below.<b></p>";         }      ?>      <input type="text" id="myinput"/><button id="mybutton">change cookie value using js</button>      <!-- make sure load jquery , jquery cookie plugin -->     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>      <script>          /* portion of code executed when user sees page (client-side) */          $(function(){             $('#mybutton').click(function(){                 $.cookie('mycookie', $('#myinput').val());                 alert(                     'the value of mycookie "'                   + $.cookie('mycookie')                   + '". now, reload page, php should read correctly.'                 );             });         });      </script> </body> </html> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -