-1

I'm accessing my script throw an URL like that

http://www.anydomain.com/code.php?a=ií

and code.php is basically this

<?php header('Content-Type: text/html; charset=utf-8'); ?>
<html><head>
    <meta charset="UTF-8">
</head><body>
<script>
    console.log('<?php echo $_SERVER['QUERY_STRING'];?>');
    console.log(unescape('<?php echo $_SERVER['QUERY_STRING'];?>'));
    console.log('<?php echo $_GET['a'];?>');
</script>
</body></html>

the logs I'm getting are:

a=i%C3%AD
a=ií

In real life I'm expecting a lot of parameters and need to save the full query, so $_SERVER['QUERY_STRING'] would be very handy. But the charset seems not to be working properly, as it is with the $_GET function.

Is there a way to get the query using $_SERVER['QUERY_STRING'] but using the charset of $_GET?

tieblumer
  • 61
  • 7
  • If this is an encoding issue, then you will have to specify what encodings are relevant here. We cannot somehow guess that. What what is the encoding you receive and what are you encoding settings in php? – arkascha Nov 18 '15 at 18:32
  • @arkascha I'm new to php, so I may be not understanding your comment, but I receive the text without any encoding (as it comes directly from the url). I also have not defined any encoding settings in php. I'll check the default encoding settings of my server... – tieblumer Nov 18 '15 at 18:42

2 Answers2

1

The problem was not at PHP at all but in the javascript function unescape. When I changed to decodeURIComponent it worked just fine.

tieblumer
  • 61
  • 7
0
$query = http_build_query($_GET);
RudiBR
  • 117
  • 10