URL parameter En-Decoding problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthias Stern

    URL parameter En-Decoding problem

    Hello!

    I've got a Javascript-PHP encoding problem.


    (1) Here is the short version:
    =============== ===============

    I'm sending a form textfield via Javascript(!) as URL parameter (GET)
    from one php-page to another and want to send all possible special
    characters like !"§$%&/()=?#öäÜ and so on to the target page. On the
    target page I read the URL-parameter via PHP and use it parameter as
    input for a MySQL LIKE command within a SELECT command.

    My problem: Special Characters are not decoded properly! I encoding on
    the source file with Javascript and encoding on the target side via PHP
    but found no way to make it work.



    (2) Here is the detailed version:
    =============== =============== ===

    I have a php-file "alphasuche_Aus wahlmaske.php". In this php-file I have
    a form with one textfield named "name".

    The entry in this textfield is used for a search in a MySQL Database.

    When the "submit"-button is pressed the entered value is passed to
    another php-file named "alphasuche.php " where the entered value is used
    for a Database search with the MySQL LIKE- command.

    Here is the Javascript(!)-command which sends the entered value to the
    "alphasuche.php " file:

    --begin--

    <script type="text/JavaScript">

    // The typical Macromedia Dreamweaver "Go To URL"-command
    function MM_goToURL() { //v3.0
    var i, args=MM_goToURL .arguments; document.MM_ret urnValue = false;
    for (i=0; i<(args.length-1); i+=2)
    eval(args[i]+".location='"+ args[i+1]+"'");
    }

    ....

    // This part sends the "name" form textfield
    MM_goToURL('par ent','alphasuch e.php?
    name='+document .form1.name.val ue+'&plz='+docu ment.form1.plz. value);

    ....

    </script>

    --end--


    So far so good. Everything is fine until I want to use special
    characters.

    It is necessary that the search-String (form field "name) can do
    following things:

    Input in "name" ... Function
    ---------------------------------------------------------------
    %xxx ... Every string matches which ends with "xxx"
    %xxx% ... Every string matches which contains "xxx"
    xxx% ... Every string matches which begins with "xxx"



    My questions
    ============

    (1) How can I get the properly decoded "name" stinrg within the php-
    file?
    (2) Which encoding do I need? Remeber: encoding in source file is done
    via Javascript - decoding in target file is done via PHP.


    Thx for any help!

    P.S.: I already spent 3 hours looking for a working solution on Google
    and PHP-forums etc.
  • R. Rajesh Jeba Anbiah

    #2
    Re: URL parameter En-Decoding problem

    Matthias Stern wrote:[color=blue]
    > (1) Here is the short version:
    > =============== ===============
    >
    > I'm sending a form textfield via Javascript(!) as URL parameter (GET)[/color]
    [color=blue]
    > from one php-page to another and want to send all possible special
    > characters like !"§$%&/()=?#öäÜ and so on to the target page. On[/color]
    the[color=blue]
    > target page I read the URL-parameter via PHP and use it parameter as
    > input for a MySQL LIKE command within a SELECT command.
    >
    > My problem: Special Characters are not decoded properly! I encoding[/color]
    on[color=blue]
    > the source file with Javascript and encoding on the target side via[/color]
    PHP[color=blue]
    > but found no way to make it work.[/color]
    <snip>

    1. In client side encodeURICompon ent()
    2. In PHP, directly getting the param like echo $_GET['foo']

    For me, the above setup seems to work without any trouble.

    --
    <?php echo 'Just another PHP saint'; ?>
    Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

    Comment

    Working...