Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    base64 encoding / JS and PHP

    I'm trying to be able to pass UTF-8 data from the client using Javascript to PHP code on the server.
    I've decide to base64 encode the data being passed.

    In Javascript, I've tried using both of these:
    http://www.webtoolkit.info/demo/java...se64/demo.html and
    http://kevin.vanzonneveld.net/techbl...base64_decode/

    Both seem to be producing equivalent results.

    My problem is with some non-English strings that I encode in Javascript, base64_decode() will fail in PHP.
    The base64_decode in Javascript returns the same string.

    For example, the Russian string:
    «НГ»: полномочия России не будут приостановлены на ближайшей сессии ПАСЕ

    base 64 encodes into (Javascript):
    wqvQndCTwrs6INC/0L7Qu9C90L7QvNC+0YfQuNGPINCg0L7RgdGB0LjQuCDQvdC1INCx0YPQtNGD0YIg0L/RgNC40L7RgdGC0LDQvdC+0LLQu9C10L3RiyDQvdCwINCx0LvQuNC20LDQudGI0LXQuSDRgdC10YHRgdC40Lgg0J/QkNCh0JU=

    But that base64 string in php fails when I run base64_decode().
    It returns false with no decoded string results.

    I'd appreciate help or suggestions about this.

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    Are you using PHP version 5.1.2. If so, there is a bug in base64_decode. please see

    http://bugs.php.net/bug.php?id=37244

    ~E

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The version I'm using of PHP is 5.2.3-1ubuntu6.3

    I've been spinning my wheels and I can't quite isolate one character or groups of characters of the original string that are causing the problem.

    I haven't seen any problems with English.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    window.escape() needs no client code, is universally supported, is remarkably fast, and char independent.

    might be worth extra 10-30% bandwidth to avoid headaches...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    escape() doesn't work with UTF-8.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    escape() doesn't work with UTF-8.
    in that case, encodeURIComponent() is about as well supported.
    It's a bit slower than escape, but still a lot faster than anything written in javascript would be.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •