Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
PHP base64_encode giving different result to Javascript btoa

I have the dummy account:
Username: giancagallardo@gmail.com
Password: Av3$truz

When I try to use PHP base64_encode using the code base64_encode($userName . ":" . $password);

I get "Z2lhbmNhZ2FsbGFyZG9AZ21haWwuY29tOkF2Mw"

When I use Javascript BTOA using the code btoa(userName + ":" + password) I get "Z2lhbmNhZ2FsbGFyZG9AZ21haWwuY29tOkF2MyR0cnV6".

I am supposed to be getting the second one in PHP, what am I doing wrong?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Since this is your code:

$userName = "giancagallardo@gmail.com";
$password = "Av3$truz";

echo base64_encode($userName . ":" . $password);

PHP is trying to get the value of $truz, change it to this:

$userName = "giancagallardo@gmail.com";
$password = 'Av3$truz'; //now it does not try to evaluate it or you could scape $ like "Av3\$truz"

echo base64_encode($userName . ":" . $password);
about 4 years ago · Juan Pablo Isaza Relatório

0

I get the same results.

echo base64_encode('hello' . ':' . 'how are you?');

PHP eval

alert(btoa('hello' + ':' + 'how are you?'));

JS Fiddle

The result is in both cases:

aGVsbG86aG93IGFyZSB5b3U/

In case you don't get the same, can you give an example, just like I did?

Note that character encoding might be a factor here, but it is probably more likely that your variables don't have the same content.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda