duanfang7270 2018-05-03 05:15
浏览 39
已采纳

是否可以将$ _SERVER变量用作HTML输入中的值?

I have a form on a site which submits to a MySQL database. What I'd like to do is collect information using hidden inputs in the form to submit information contained in PHP $_SERVER variables to the database. I've already tried to do so like this:

<input type="hidden" value="$_SERVER['REMOTE_ADDR']">

I quickly realized why that didn't work. However, I don't know the correct way to submit information from $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_TIME'] and other variables into my database.

The main idea is to use these hidden inputs to submit info from the client like IP address and form submission time. Any idea what I need to do?

  • 写回答

2条回答 默认 最新

  • dpa31905 2018-05-03 05:52
    关注

    You need to go through these steps instead of playing around at client end to get the SERVER details.

    $_SERVER is used to fetch all the detailed information about the server as its a reserved variable in PHP and comes under the category of SuperGlobals.

    $_SERVER is an array containing information such as headers, paths, and script locations.

    In your case when the form is being submitted to some action(function) at the server end, from there you can get the details of server and its host using $_SERVER['HTTP_HOST'] and then pass it to your database.

    Hope it helps.

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

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下