Insert value received in javascript

Asked

Viewed 71 times

0

I have the following code:

  <p>Your browser fingerprint: <strong id="fp"></strong></p>
  <p>Time took to calculate the fingerprint: <var id="time"></var> ms</p>

<script type="text/javascript">
var hasConsole = typeof console !== "undefined"

    var fingerprintReport = function () {
      var d1 = new Date()
      Fingerprint2.get(function(components) {
        var murmur = Fingerprint2.x64hash128(components.map(function (pair) { return pair.value }).join(), 31)
        var d2 = new Date()
        var time = d2 - d1
        document.querySelector("#time").textContent = time
        document.querySelector("#fp").textContent = murmur
        var details = ""
        if(hasConsole) {
          console.log("time", time)
          console.log("fingerprint hash", murmur)
        }
        for (var index in components) {
          var obj = components[index]
          var line = obj.key + " = " + String(obj.value).substr(0, 100)
          if (hasConsole) {
            console.log(line)
          }
          details += line + "\n"
        }
        document.querySelector("#details").textContent = details
      })
    }

    var cancelId
    var cancelFunction

    // see usage note in the README
    if (window.requestIdleCallback) {
      cancelId = requestIdleCallback(fingerprintReport)
      cancelFunction = cancelIdleCallback
    } else {
      cancelId = setTimeout(fingerprintReport, 500)
      cancelFunction = clearTimeout
    }
</script>

In the form I receive this values:

Your browser fingerprint: e18982228d92dbaaf8d72492f16a059c

Time Took to calculate the fingerprint: 142 ms

Now I want to take these values and insert them into mysql automatically on login.

I’m trying this way, but you’re not inserting:

$teste1 = $_SESSION['usuarioId'];
 $teste4 = $_POST["fp"];
 var_dump($teste4);

if($teste4 != ''){
$query1 = 'UPDATE raddb.sessoes SET hostname= ? WHERE id = ? ';
$stmt1 = $conn->prepare( $query1 );
$stmt1->bind_param("ss", $teste4, $teste1); 
$stmt1->execute();
}

The problem is that when I do var_dump($teste4); returns as NULL. Not receiving variable value fp within the javascript

1 answer

0

Changes here:

 $teste4 = $_POST["fp"];

To

 $teste4 = $_POST["murmur"];
  • even by changing the variable test4 becomes NULL

  • The call to the POST function in your code has to be next to Fingerprint2.get(function(components) { }), for example: Fingerprint2.get(function(components) { ... postFingerprint(murmur); })

  • can update the response of how to put this part of the code inside the javascript?

  • Put all your code on so I can get a good look at it

  • the code I have is this, and it works well, returns the identification of each device, the problem is just enter this value e18982228d92dbaaf8d72492f16a059c in the database

Browser other questions tagged

You are not signed in. Login or sign up in order to post.