javascript - Set java script value to php session and get session value onto another php file -
i'm trying set javascript value php session variable , session value php page. here code. on same show value using alert. here's first page index_1.php
<script> function(no_user){ `var num_user = no_user; '<?php $_session["num_user"] = "' + no_user+ '"; ?>'; //alert('<?php echo $_session["num_user"] ?>');*/ window.open("demo.php"); } </script>
another page index_2.php
<?php if(isset($_session['num_user'])){ $a = $_session['num_user']; echo "number of user: ". $a; ?>
you can not set php variable in js seek set location(demo.php)
<script> function(no_user){ var num_user = no_user; window.open("demo.php?no_user="+no_user); //or window.location = 'index2.php?no_user'+no_user; } </script>
and set session on demo.php/index2.php
session_start(); if(!empty($_get['no_user'])) { $_session['num_user']= $_get['no_user']; }
javascript php session-cookies
No comments:
Post a Comment