php php中的隐藏字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4949847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:20:43  来源:igfitidea点击:

hidden field in php

phphtml

提问by user550265

For hidden fields, can i use a field of the type

对于隐藏字段,我可以使用该类型的字段吗

<input type="hidden" name="field_name" value="<?php print $var; ?>"/>

and retrieve it after the GET / POST method as $_GET['field_name'] / $_POST['field_name'] ?

并在 GET / POST 方法后检索它 $_GET['field_name'] / $_POST['field_name'] ?

are there any other ways of using hidden fields in php?

有没有其他方法可以在 php 中使用隐藏字段?

回答by Nicholas Kreidberg

You absolutely can, I use this approach a lot w/ both JavaScript and PHP.

你绝对可以,我在 JavaScript 和 PHP 中经常使用这种方法。

Field definition:

字段定义:

<input type="hidden" name="foo" value="<?php echo $var;?>" />

Access w/ PHP:

使用 PHP 访问:

$_GET['foo'] or $_POST['foo']

Also: Don't forget to sanitize your inputs if they are going into a database. Feel free to use my routine: https://github.com/niczak/PHP-Sanitize-Post/blob/master/sanitize.php

另外:如果您的输入进入数据库,请不要忘记清理它们。随意使用我的例程:https: //github.com/niczak/PHP-Sanitize-Post/blob/master/sanitize.php

Cheers!

干杯!

回答by Jim W.

Yes, you can access it through GETand POST(trying this simple task would have made you aware of that).

是的,您可以通过GET和访问它POST(尝试这个简单的任务会让您意识到这一点)。

Yes, there are other ways, one of the other "preferred" ways is using sessions. When you would want to use hidden over session is kind of touchy, but any GET / POST data is easily manipulated by the end user. A session is a bit more secure given it is saved to a file on the server and it is much harder for the end user to manipulate without access through the program.

是的,还有其他方式,其他“首选”方式之一是使用session。当您想要使用隐藏会话时有点棘手,但最终用户很容易操纵任何 GET / POST 数据。会话更安全,因为它被保存到服务器上的文件中,并且最终用户在不通过程序访问的情况下进行操作要困难得多。

回答by Felix Kling

Can I use a field of the type ... and retrieve it after the GET / POST method ...

我可以使用...类型的字段并在 GET / POST 方法之后检索它吗...

Yes (haven't you tried?)

是的(你没试过吗?)

Are there any other ways of using hidden fields in PHP?

在 PHP 中还有其他使用隐藏字段的方法吗?

You mean other ways of retrieving the value? No.
Of course you can use hidden fields for what ever you want.

您的意思是其他检索值的方法?不
。当然,您可以根据需要使用隐藏字段。



Btw. inputfiels have no end tag. So write either just <input ...>or as self-closing tag <input .../>.

顺便提一句。input字段没有结束标签。所以要么只写要么<input ...>写成自闭标签<input .../>