douyong7199 2017-01-31 23:57 采纳率: 0%
浏览 107
已采纳

如何使用get方法使用PHP输入表单字段的值

I have the following code snippet of my fields I have in my form:

       <input id="username" type="text" placeholder="E-mail Address" value="" name="username"></input>

This is what I have in my input field. Is there anybody who will tell me how to get input values to the field using a url? e.g https://mysite?username=ken and it will show "ken" in the input field?

  • 写回答

3条回答 默认 最新

  • doukengzi3517 2017-02-01 00:00
    关注

    In your HTML, add the input field like this:

    <input type="text" name="username" value="<?php echo htmlspecialchars($_GET['username']); ?>" />
    

    Basically, the value attribute of the text field needs to be set to:

    <?php echo $_GET['username']; ?>
    

    The code right above this is how you would output a get variable in php whether you are putting it in a text field or not. To access get variables, always use:

    $_GET['variable_name'];
    

    Then you can assign it to variables or pass it as a function parameter.

    **However, I strongly do not recommend passing sensitive information like usernames and passwords through GET variables. **

    First off, users could change the URL hence changing the variable. They could also accidentally share the URL with someone and that could give someone else access to their account. I would recommend that you create a cookie on their machine that is set to a random ID, and then in a MySQL database, associate that ID with a username so that you know the user can't accidentally share their account or change their username through the URL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用