include this in php code. To migrate from php to more or less pure javascript