From: Operating system: PHP version: Irrelevant Package: *General Issues Bug Type: Feature/Change Request Bug description:Provide encode/decode functions for RFC 4648 "base64url" format
Description: ------------ Including Base64-encoded data in URLs and file names is a commonly encountered task. The PHP base64_encode() function is not suitable for this, since its output may encode the characters "+" (which has special meaning in URL query parameters) and "/" (which is used as a path separator in file names and URL paths). RFC 4648 (http://tools.ietf.org/html/rfc4648) defines, in section 5, a standard variant of Base64 encoding, called "base64url", for this purpose. It differs from the usual "base64" format in that the characters "+" and "/" are replaced with "-" and "_" respectively, and that the use of the padding character "=" is optional and not usually recommended. I would like to suggest that functions for encoding and decoding data in this format be provided in PHP alongside the existing base64_encode() and base64_decode() functions. Although such functions can be relatively easily implemented in pure PHP code based on the existing Base64 encoding functions, a built-in implementation would presumably be both more efficient and more likely to be user correctly by script authors. A sample PHP implementation of the proposed functions (which could be included in the documentation for backward compatibility purposes) is included below: function base64url_encode( $data, $pad = false ) { $base64 = strtr( base64_encode( $data ), '+/', '-_' ); return ( $pad ? $base64 : rtrim( $base64, '=' ) ); } function base64url_decode( $base64, $strict = false ) { return base64_decode( strtr( $base64, '-_+/', '+/-_' ), $strict ); } -- Edit bug report at https://bugs.php.net/bug.php?id=61982&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61982&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61982&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61982&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61982&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61982&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61982&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61982&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61982&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61982&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61982&r=support Expected behavior: https://bugs.php.net/fix.php?id=61982&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61982&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61982&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61982&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61982&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61982&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61982&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61982&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61982&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61982&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61982&r=mysqlcfg