doucai1901 2013-11-24 17:49
浏览 45

传递URL中的数据与使用GET通过表单提交

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.

  • 写回答

1条回答 默认 最新

  • douchang8219 2013-11-24 18:30
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制