Retrieve $_POST data to send to javascript without using localize script

You can use set_transient to write temporary data to the database and get_transient to read the value back. This keeps the data on the server and available across requests. It’s kind like a nonce. Keep in mind writing to your database can jam things up when you get a significant amount of users.


If you want to pass hashed data from PHP to Javascript you could use Hashids — assuming your data is numeric positive numbers.

PHP

$hashids = new Hashids\Hashids('this is my salt');
$id = $hashids->encode(1, 2, 3);
$numbers = $hashids->decode($id);

JavaScript

var hashids = new Hashids("this is my salt"),
id = hashids.encode(1, 2, 3),
numbers = hashids.decode(id);

If you decode anywhere in the JavaScript then someone could potentially get ahold of the salt so it’s best to use it only to transport the data.

If you want some random salt, there is an online generator or use wp_salt(). You can also take a look at the way wp_create_nonce() works by adding the logged in user’s ID to the salt.


Alternates – some sites warn against using MD5 while others show hashing with openssl.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)