The purpose of this short article is to show you how you can encode something in PHP and then decode it with javascript. And we will also cover how to encode in Javascript and Decode in PHP.

Encoding and Decoding is very helpful to add a little bit of security to the information you exchange between your files and your websites. It is essential when you have ajax calls. This are the four functions you will need to start decoding your information and encoding. Very simple to use


  • btoa() to encode Binary to ASCII.
  • atob() to decode ASCII to binary.


  • base64_encode()
  • base64_decoded() - After decoding, you must also use the urldecode($sring) on the decoded string as the btoa() function encodes url

If you have any questions, please let us know.