简体   繁体   English

回声值进入隐藏字段?

[英]Echo value into hidden field?

I am trying to find out and track what browser and if a proxy is being used when I receive form submissions. 我试图找出并跟踪什么浏览器,以及在收到表单提交时是否正在使用代理。 I have the following code below: 我下面有以下代码:

<?php

$browser = $_SERVER['HTTP_USER_AGENT'];
$ip_address = $_SERVER['REMOTE_ADDR'];
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
    $ip_address = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
}

?>

For example I tried the below but it does not work. 例如,我尝试了以下方法,但它不起作用。 It is not submitting any data with my form. 它没有使用我的表单提交任何数据。

What am I doing wrong? 我究竟做错了什么?

echo ('<input type="hidden" name="browser" value="' . $browser . '" />' );
echo '<input type="hidden" name="browser" value="'.$browser.'">'

What am I doing wrong? 我究竟做错了什么?

  • You are not referencing the variable with a $ 您没有用$引用变量
  • You need to correctly escape the variable value from the string 您需要正确地从字符串中转义变量值

Try printf 试试printf

printf('<input type="hidden" name="browser" value="%s">', $browser);

试试这个

echo ("<input type='hidden' name='browser' value='".$browser."'");
echo ('<input type="hidden" name="browser" value="'.$browser.'">');

试试this -> value="'.$browser.'"这样的东西

You are combining echo and print (which both do the same) into one call. 您正在将echo和print(两者都做相同)组合到一个调用中。 For another thing, you haven't closed the input element HTML (notice the final greater than sign I've added): 另外,您还没有关闭输入元素HTML(注意最后一个大于我添加的符号):

echo ('<input type="hidden" name="browser" value="' . $browser . '" />' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM