douxiong5972 2017-01-25 00:29
浏览 95

使用Base64enconde和解码时的奇怪值

I m building an website and i'm using the base64encode() and base64decode(). I send the base64encode(value) through and url and i receive and then i decode the value. On the page that i have the decoded value i have one button that goes to the previous page and i use the encode to encode again the value and send it. the previous page i decode that value and i encode again to send to the same page.

At the first time i receive the correct values but when i do more than 1 i get strange value. It is my code:

The first page: Here i receive one value and i decode it.

$tablename = base64_decode($_GET['tablename']);

In the end of the page i have on list with this code, here i send the encoded value:

$descricao = base64_encode($row["descricao"]);
              $tablename = base64_encode($tablename);
              ?>
                <a href="./gestaoalarme.php?descricao=<?=$descricao?>&tablename=<?=$tablename?>">

In the seconde page i receive the encoded value

$tablename=base64_decode($_GET['tablename']);

and i have that button that goes back and send the encode value.

 <a href="./verdispositivos.php?tablename=<?=base64_encode($tablename)?>" class="btn Back btn-lg">

The first time results, but then not.

  • 写回答

1条回答 默认 最新

  • douguan1887 2017-01-25 00:36
    关注

    Base64 encoded values are not URL safe due to the + / and = characters.

    You will also need to use urlencode() before using the string in a url.

    E.g.

    $value_to_encode = 'some=string/here+foobar';
    $encoded = urlencode(base64_encode($value_to_encode));
    $decoded = base64_decode(urldecode($encoded));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入