Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-25-2008, 11:21 PM   PM User | #1
ghernando
New to the CF scene

 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ghernando is an unknown quantity at this point
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.
ghernando is offline   Reply With Quote
Old 09-25-2008, 11:26 PM   PM User | #2
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
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
ess is offline   Reply With Quote
Old 09-26-2008, 05:25 AM   PM User | #3
ghernando
New to the CF scene

 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ghernando is an unknown quantity at this point
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.
ghernando is offline   Reply With Quote
Old 09-26-2008, 08:37 AM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Old 09-27-2008, 06:13 AM   PM User | #5
ghernando
New to the CF scene

 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ghernando is an unknown quantity at this point
escape() doesn't work with UTF-8.
ghernando is offline   Reply With Quote
Old 09-27-2008, 08:30 AM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:51 AM.


Advertisement
Log in to turn off these ads.