我认为这将是一个简单的谷歌搜索,但我的技术似乎并不像我想象的那么普遍.
I thought this will be an easy Google-search, but it seems that my technique is not as common as I thought.
我如何在 JavaScript 中 encode 一个 Base64 字符串,以便将它安全地放在带有 GET 参数的行上(我的 Base64 字符串包含很多/、+ 和=,decodePHP中的相同字符串,以便将其存储在数据库中?
How can I encode a Base64 string in JavaScript, in order to 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 store it in a database?
当我发布没有编码的 Base64 字符串时,我的 PHP 脚本不接受它.
When I post the Base64 string without encoding, my PHP script does not accept it.
我找到了一个解决方案来编码和解码Base64字符串在 JavaScript 中,但对我来说没有意义.
I found a solution for encoding and decoding the Base64 string in JavaScript, but not in the way it makes sense for me.
所以在 javascript 中(更新为编码 URI):
So in javascript (updated with encoding URI):
var myStr = "I am the string to encode";
var token = encodeURIComponent(window.btoa(myStr));
btoa 示例
然后您应该能够将该 base64 编码的字符串添加到您的获取请求中.
You should be then able to add that base64 encoded string to your get request.
然后在 PHP 中,在您检索请求之后:
Then in PHP, after you retrieve the request:
<?php
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode(urldecode($str));
?>
base64_decode 文档
这篇关于用 JavaScript 编码 Base64,用 GET 发送,用 PHP 解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)