doufei1988 2016-03-21 18:53
浏览 182

fingerprintjs2到php变量

I like to get fingerprint as php variable, I get the follow but do not want to work.

<p>fingerprint2: <strong id="fp2"></strong></p>

<script src="/fingerprintjs2/fingerprint2.js"></script>
<script>
    var fp2 = new Fingerprint2();
    fp2.get(function(result) {
        console.log(result);
        $("#fp2").text(result);
    });
</script>

$myphpvar = "<script>document.write(fp2.get());</script>"; 

echo $myphpvar;
  • 写回答

3条回答 默认 最新

  • douna1941 2016-03-21 19:00
    关注

    The Javascript is run after the PHP has completed. Client side VS server side code. I have solved this in the past by running the PHP within a PHP file that renders an image. This method is often referred to pixel tracking.

    Here are the basics, you need to pass your variables in Javascript to a PHP file that renders an image:

    document.write("<img src=fingerprint.php?x="+x+"&y="+y+" width=1 height=1>");
    

    In the above case it passed Javascript variables x and y to the PHP image.

    Then the fingerprint.php script looks like:

        <?php
        header("Content-type: image/png");
        session_start();
    
        $x = $_REQUEST['x'];
        $y = $_REQUEST['y'];
    
        $_SESSION['x'] = $x;
        $_SESSION['y'] = $y              
    
        // SHOW THE IMAGE
        $im      = imagecreatefrompng("fingerprint.png");
    
        imagepng($im);
        imagedestroy($im);
    
        ?>
    

    The png image can be anything you want as it will just be a 1 x 1 image on your final screen. You now have the Javascript variables in your PHP. As the code starts a session you could write the variables to a session and collect them later in another script, or write them to a database and recover later. Try with my simple example to ensure you have it working then expand from there.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大