Encode Base64 in JavaScript, send with GET, decode in PHP

非 Y 不嫁゛ 提交于 2019-12-02 06:04:22

So in javascript (updated with encoding URI):

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

btoa example

You should be then able to add that base64 encoded string to your get request.

Then in PHP, after you retrieve the request:

<?php
   $str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
   echo base64_decode(urldecode($str));
?>

base64_decode docs

In Javascript

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

In php

$password = urldecode(base64_decode($_POST['password']));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!