douhui4699 2014-11-14 06:39
浏览 35

将java脚本值设置为php会话并将会话值转换为另一个php文件

I'm trying to set the JavaScript value to a PHP Session variable and get this session value to another php page. here my code. on the same it will show the value using alert. here's my 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;

?>
  • 写回答

2条回答 默认 最新

  • donglinyi4313 2014-11-14 06:49
    关注

    You can not set php variable in js try to set it another 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'];
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示