-1

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.

Bruno Gonçalves
  • 55
  • 2
  • 2
  • 11

1 Answers1

1

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));
Community
  • 1
  • 1
Felix Eve
  • 3,811
  • 3
  • 40
  • 50