Window Btoa() Method

I thought this will be an easy Google-tìm kiếm, but it seems that my technique is not as common as I thought.

Bạn đang xem: Window btoa() method

How can I encode a Base64 string in JavaScript, in order to lớn put it safely on the line with a GET parameter (my Base64 string contains a lot of /, + and =, and decode the exact same string in PHP.., in order to lớn store it in a database?

When I post the Base64 string without encoding, my PHPhường script does not accept it.

I found a solution for encoding and decoding the Base64 string in JavaScript, but not in the way it makes sense for me.

Xem thêm: Hướng Dẫn Tải Game Jump Force Full Update Dlc V1, Game Jump Force V2


So in javascript (updated with encoding URI):

var myStr = "I am the string to lớn encode";var token = encodeURIComponent(window.btoa(myStr));btoa example

You should be then able khổng lồ add that base64 encoded string to lớn your get request.

Then in PHP.., after you retrieve sầu the request:

base64_decode docs


In Javascript

var password ="xyz"window.btoa(password)In php

$password = urldecode(base64_decode($_POST<"password">));


Thanks for contributing an answer to Stachồng Overflow!

Please be sure to lớn answer the question. Provide details & giới thiệu your research!

But avoid

Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; bachồng them up with references or personal experience.

To learn more, see our tips on writing great answers.

Post Your Answer Discard

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy và cookie policy

Not the answer you're looking for? Browse other questions tagged javascript php encoding get base64 or ask your own question.


site design / hình ảnh sản phẩm © 2021 Staông xã Exchange Inc; user contributions licensed under cc by-sa. rev2021.8.23.40047

Staông xã Overflow works best with JavaScript enabled

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device & disclose information in accordance with our Cookie Policy.