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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?