dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Sending the "+" as %2b in as3??????

Hybrid View

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    16

    Question Sending the "+" as %2b in as3??????

    I have a login form that is sending an email address and password to a PHP script.

    Whenever someone enters the "+" character in either field (including gmail users who are putting a "+" in the email address for sorting), the "+" character gets encoded to "%20" in the string being sent to the PHP when it needs to be converted to "%2b"

    I know that this is happening because "+" and "%20" both represent a "space" in the format, so how do I force Flash to convert those plus signs properly before submitting the string to the script?

    I am assuming if I run a for loop on the string, and convert all "+" signs into a "%2b" before creating the string then that is going to end up being converted to "%252b" as the percent sign will get encoded after converting the "+" sign.

    I cannot find anything with Google searches other than many other people have this problem and there are supposedly no solutions for it?

    This will be a problem if a user has a "+" symbol in their password, or if they are using a gmail or other email account where the "+" symbol is allowed.

    Any clues or pointers in the right direction on how to deal with this would be greatly appreciated.

  2. #2
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    Could you convert the whole field to hex (each character being 2 hex digits), send that to the PHP script and have the script convert back to ASCII characters?

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    16
    How easy is it to convert the String value of a text field into a hex value?

    I quickly looked and could not find any references on how to do that.

    And, after converting it into a hex value, won't the encoding that happens when the URLVariables are posted change any % signs into its unicode or hex value?

  4. #4
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    PHP Code:
    function stringToHex(string:String):String{
        var 
    hexString:String "";
        var 
    sub:String;
        for (var 
    0i<string.lengthi++){
            
    sub string.charCodeAt(i).toString(16)
            
    hexString+=sub.length == 2?sub:"0"+sub;
        }
        return 
    hexString
    }

    trace(stringToHex("Hello")); //  48656c6c6f 
    Just pass the hex string (i.e. "48656c6c6f") to the PHP script and have it do the reverse.

    And no the encoding won't mess it up, because there won't be any % signs, it'll just be alpha-numeric characters.

    That said, there should be a better way of just sending raw text to the PHP script with POST that I'm not aware of?
    Last edited by Schfifty Five; 05-26-2009 at 01:50 PM.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center