BASE64 Encoding in PHP
Posted: Fri Sep 04, 2009 2:41 am
Encoding
Result will be : NDUx
Decoding
Use serialize with base64_encode to convert the more complex data in to network transferable data.
In .Net, this type of encoding is available at Viewstate
The problem here is, when Encoding a text into bas64, the '=' char is added and php scritpt is confused.
To avoid this, the following method can be used.
Code: Select all
base64_encode ('451');
Decoding
Code: Select all
echo base64_decode('NDUx');
In .Net, this type of encoding is available at Viewstate
The problem here is, when Encoding a text into bas64, the '=' char is added and php scritpt is confused.
To avoid this, the following method can be used.
Code: Select all
function base64_url_encode($input)
{
return strtr(base64_encode($input), '+/=', '-_,');
}
function base64_url_decode($input)
{
return base64_decode(strtr($input, '-_,', '+/='));
}