By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,978 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,978 IT Pros & Developers. It's quick & easy.

URL parameter En-Decoding problem

P: n/a
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_Auswahlmaske.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_returnValue = 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('parent','alphasuche.php?
name='+document.form1.name.value+'&plz='+document. 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.
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Matthias Stern wrote:
(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.

<snip>

1. In client side encodeURIComponent()
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/

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.