Breaking News
Loading...
September 27, 2014

Base64 Encode and Base64 Decode PHP for GET parameters

12:10 PM
<?php
/**
   * Base64 encoding that doesn't need to be urlencode()ed.
   * Exactly the same as base64_encode except it uses
   *   - instead of +
   *   _ instead of /
   *   No padded =
   *
   * @param string $input base64UrlEncoded string
   * @return string
   */

function base64UrlDecode($input) {
    return base64_decode(strtr($input, '-_', '+/'));
  }

/**
   * Base64 encoding that doesn't need to be urlencode()ed.
   * Exactly the same as base64_encode except it uses
   *   - instead of +
   *   _ instead of /
   *
   * @param string $input string
   * @return string base64Url encoded string
   */

function base64UrlEncode($input) {
    $str = strtr(base64_encode($input), '+/', '-_');
    $str = str_replace('=', '', $str);
    return $str;
  }

?>

0 comments:

Post a Comment

 
Toggle Footer