How to pass friendly base64 encoded strings in URL

Warning message

JQuery Cycle must be installed in order to run the slideshow. Please go to Status Report for instructions.

Primary tabs

If you encode with base64 and provide in URL, its not user friendly because they will not appear as proper link. By default it produces a string which contains characters like "+", "=" and "/" which will not let it become a URL with underline. Even you use to generate in emails, only the sub part of your URL will appear as URL with underline and rest will be ignored and appeared as weird characters.

If you want to use it in URL string and get the values as $_GET or even use it in email, you need to make two custom functions for encoding and decoding:

// For Encoding
function base64url_encode($data) { 
  return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); 
} 

// For Decoding
function base64url_decode($data) { 
  return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT)); 
}