Since PHP runs on the server before JavaScript runs in the browser, you can't access it directly. You'll have to send the data from the client back to a PHP script. The best way is using an AJAX request, like fetch()
. Your PHP script can then easily access it using $_POST
.