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条)

报告相同问题?