duanoucuo7045 2014-06-05 18:01
浏览 21

多字$ GET变量problemin PHP

I am currently writing some search engine, where this page is retrieving some _GET variables from a previous page. This is working as intended.

Now I am using those variables as default value in a POST form. However, for some reason, only the first word for each of them is showing up. The form code is as follows:

<form action = "insert.php" method = 'POST'>
<Place name <input type="text" name="name" size = "30" value= <?php echo $_GET['name']; ?> />

Note that when echoing $_GET['name'] anywhere else in the page, everything is fine. Multiple words show up as expected, but when I use it as a text box default value, only the first word shows up on the textbox.

At first, I thought it had something to do with the way those $_GET variables are sent in the URL so I tried this:

$fullname = array();

 $fullname = explode("%20", $_GET['name']);

 $aaa = implode (' ',$fullname);

...

Place name <input type="text" name="name" size = "30" value= <?php echo $aaa; ?> />

but the result is still the same. If I echo it anywhere else in the page I get the full string, but if it's inside the form only the first word shows up.

What am I missing here?

  • 写回答

1条回答 默认 最新

  • dongluan7821 2014-06-05 18:03
    关注

    The value attribute of the input tag needs to be in quotes:

    <input type="text" name="name" size = "30" value="<?php echo $_GET['name']; ?>" />"
    

    Otherwise, if $_GET['name'] contains spaces you'll end up with something like: value=John Smith. That will be understood as value=John with an invalid Smith attribute floating around.

    Also, consider sanitizing $_GET['name'] with htmlspecialchars. Consider what would happen if $_GET['name'] was "/><script>alert(0)</script><. You'd end up embedding user-controlled code on your website, resulting in a reflected XSS.

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
  • ¥15 电视版的优酷可以设置电影连续播放吗?
  • ¥50 复现论文;matlab代码编写
  • ¥30 echarts 3d地图怎么实现一进来页面散点数据和卡片一起轮播
  • ¥15 数字图像的降噪滤波增强
  • ¥15 心碎了,为啥我的神经网络训练的时候第二个批次反向传播会报错呀,第一个批次都没有问题
  • ¥15 MSR2680-XS路由器频繁卡顿问题
  • ¥15 VB6可以成功读取的文件,用C#读不了
  • ¥15 如何使用micpyhon解析Modbus RTU返回指定站号的湿度值,并确保正确?
  • ¥15 C++ 句柄后台鼠标拖动如何实现