Take the 2-minute tour ×

I have written a small php (test.php) that reads and displays the data passed to it.

<?php $name = $_GET['name']; echo $name;?>

When I execute the following URL http://localhost/test.php?name=Géo

The text that gets displayed is: G�o

However, when I submit "Géo" from another webpage:

<form method="get" action="test.php"> <input type="test" name="name"> <input type="Submit"> </form>

the URL changes to http://localhost/test.php?name=G%C3%A9o

and now the correct text is displayed:Géo

In the first scenario, only when I add utf8_encode( $_GET['name']), the correct text (Géo) gets displayed.

My question: Is it possible to know how the data was passed, submitting via a form or directly from the URL. If not then what changes should I make to the webpage so that both the scenarios are handled correctly i.e. display Géo in both the cases.

Thanks for your help.

share|improve this question
In the second scenario, the addition utf8_encode( $_GET['name'] ) changes the input? –  MeNa Nov 24 '13 at 18:04
Adding utf8_encode to the second scenario changes the input to: GÃ©o –  user3027793 Nov 24 '13 at 18:08
What is your "Content-Type" header? its contains something like charset=UTF-8? –  MeNa Nov 24 '13 at 18:15
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">; <html xmlns="w3.org/1999/xhtml"; xml:lang="en" lang="en"> <head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> </head> –  user3027793 Nov 24 '13 at 18:17

1 Answer 1

You can add a reg. expression that will check if the parameter contain %. Because that the encoded parameter probably contains a %.

But, if you'll execute url that for some reason contains a %, the problem will comeback...

share|improve this answer
I am wondering how is everybody else solving this problem? –  user3027793 Nov 24 '13 at 18:54
Probably dont cares about execute without html form. –  MeNa Nov 24 '13 at 18:57
See Google, type in Géo or % in the search box and then change the URL to google.com?q=% or google.com?q=Géo In both the scenarios correct data is spit out. –  user3027793 Nov 24 '13 at 19:00

Your Answer


