URL parameter En-Decoding problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


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:


<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)


// This part sends the "name" form textfield




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

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-
(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.

Re: URL parameter En-Decoding problem

Matthias Stern wrote:
Quoted text here. Click to load it


   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 /

Site Timeline