首页 \ 问答 \ 检查提交值是否在数组中?(Check wheter submitting value is in array?)

检查提交值是否在数组中?(Check wheter submitting value is in array?)

我最近读过一篇文章说,你永远不应该信任发送数据中的用户。

所以我们假设我有以下表单输入:

<label for="input1">Answer 1</label>
<input type="radio" name="question1" value="answer1" id="input1" />
<label for="input2">Answer 2</label>
<input type="radio" name="question1" value="answer2" id="input2" />
<label for="input3">Answer 3</label>
<input type="radio" name="question1" value="answer3" id="input3" />

是否可以检查发布的答案是否在回答里面:

$question1_answers = array("answer1", "answer2", "answer3");
$answer1 = $_POST['question1'];
if ( in_array($answer1, $question1_answers) ) {
    echo "OK!";
} else {
    echo "Please select proper answer!";
}

或者,也许上面的代码是不必要的,我应该简单地阅读$_POST['question1'] ,这将足够?


I have recently read an article that said, that you should never trust user in the sending data.

So let's say that I have following form inputs:

<label for="input1">Answer 1</label>
<input type="radio" name="question1" value="answer1" id="input1" />
<label for="input2">Answer 2</label>
<input type="radio" name="question1" value="answer2" id="input2" />
<label for="input3">Answer 3</label>
<input type="radio" name="question1" value="answer3" id="input3" />

Is it okay to check whether posted answer is inside aray with answers:

$question1_answers = array("answer1", "answer2", "answer3");
$answer1 = $_POST['question1'];
if ( in_array($answer1, $question1_answers) ) {
    echo "OK!";
} else {
    echo "Please select proper answer!";
}

Or maybe above code is unnecessary and I should simply read $_POST['question1'] and it will be enough?


原文:https://stackoverflow.com/questions/12814021
更新时间:2022-05-23 14:05

最满意答案

要获得Vbox-log,您需要:

1)添加AutoConfig.kmk

 VBOX_WITH_R0_LOGGING := 1    

2)编译

kmk BUILD_TYPE=debug  

3)然后,
你应该设置环境变量

VBOX_LOG (what kind of module you want to see in your log)  
VBOX_LOG_FLAGS  
VBOX_LOG_DEST (location of log)  

更多信息: https//www.virtualbox.org/wiki/VBoxLogging
之后你应该从这个终端窗口运行VirtualBox。

3 - 例如

export VBOX_LOG_DEST="dir=/home/guest/tmp"  
export VBOX_LOG=hgcm.e.l.f  
export VBOX_LOG_FLAGS="buffered thread msprog" (optionaly)  

To get Vbox-log you need:

1) To add in AutoConfig.kmk

 VBOX_WITH_R0_LOGGING := 1    

2) Compile with

kmk BUILD_TYPE=debug  

3) Then,
you should set environment variable

VBOX_LOG (what kind of module you want to see in your log)  
VBOX_LOG_FLAGS  
VBOX_LOG_DEST (location of log)  

more info there : https://www.virtualbox.org/wiki/VBoxLogging
And after it you should run VirtualBox from this terminal window.

3 - For example

export VBOX_LOG_DEST="dir=/home/guest/tmp"  
export VBOX_LOG=hgcm.e.l.f  
export VBOX_LOG_FLAGS="buffered thread msprog" (optionaly)  

相关问答

更多
  • 因此,VirtualBox IRC频道irc://chat.freenode.net/#vbox上的某个人告诉我,客人新增功能在Chrome操作系统上无法使用。 在尝试了@sarnold的建议后,运行了mount -oremount,rw / ,我被告知 Unable to determine your Linux distribution So someone on the VirtualBox IRC channel irc://chat.freenode.net/#vbox told me that ...
  • 要获得Vbox-log,您需要: 1)添加AutoConfig.kmk VBOX_WITH_R0_LOGGING := 1 2)编译 kmk BUILD_TYPE=debug 3)然后, 你应该设置环境变量 VBOX_LOG (what kind of module you want to see in your log) VBOX_LOG_FLAGS VBOX_LOG_DEST (location of log) 更多信息: https : //www.virtualbox ...
  • 我有它....因为我在虚拟机上,我必须将我的网络适配器设置设置为桥接适配器而不是NAT。 在设置为桥接适配器后,我的guest mac os的IP也发生了变化,现在它看起来像192.168.8.103,这与我之前获得的不同,这个IP可以从Windows主机访问,我可以远程登录。 这可能会帮助其他人遇到类似的麻烦并节省一些时间。 I have got it....as I'm on virtualbox, I have to set my network adapter setting to bridge a ...
  • 您在构成您的nixos配置或模块的fileSystems两次定义fileSystems 。 在第一个定义中它是一个列表,而在第二个定义中,通过使用嵌套属性集合速记符号将fileSystems定义为attrset。 实际上,这个错误是由Nix语言而不是NixOS模块系统产生的。 通过使用与/virtualboxshare相同的符号定义所有文件系统,可以解决此错误。 为了更好地理解嵌套的attrsets,使用nix repl可能会很有用: $ nix repl Welcome to Nix version 2. ...
  • 首先,VirtualBox不会为您的主机创建串行端口。 因此,您必须使用其他软件在主机上创建两个虚拟COM端口,并虚拟地桥接这两个端口。 然后使用一个端口连接到Simulink,其他必须以VM COM端口使用此端口的方式进行设置。 为了在Windows上创建虚拟COM端口,我将使用伪造RS232串行端口的 com0com 。 您可以使用任何您喜欢的软件。 安装com0com后,从C:\Program Files (x86)\com0com 。 现在点击申请。 现在你将COM10和COM10桥接(就像COM9 ...
  • 这个问题似乎不是一个错误,而是我的误解。 This issue seems to not be a bug but my misunderstanding.
  • 您的外部IP是否静态与访问LAN上的虚拟化服务器无关。 将VirtualBox设置为桥接模式。 只需确定计算机的DHCP选择的内部IP(通常为192.168.1.SOMETHING ),并将最后一个数字替换为小于250的另一个数字。例如,如果您的计算机是192.168.1.6可以在VM上正常工作(选择一个高数字来消除冲突)。 使用控制面板 - >适配器设置进行设置。 重新启动VM。 以192.168.1.70(或您之前选择的地址)连接到MySQL。 注意:如果您的计算机的地址位于不同的子网(192.168. ...
  • 我的猜测是,虽然您的代码只占用一个核心,但执行时您的程序可以在操作系统执行期间切换到不同核心的上下文中。 这就是为什么你看到所有核心使用,但尖峰发生在不同的时间。 (但这样做比测量资源监视器更准确)。 My guess is that while your code only takes one core, your program when executed can be switched into and out of context on different cores during the exec ...
  • 访问[开始菜单]并在[搜索程序和文件]中键入运行 。 在[运行行]里面输入gpedit.msc 。 在那里,转到Windows设置 - >安全设置 - >本地策略 - >安全选项 - > [ 帐户:限制本地帐户使用空白密码仅控制台登录 ]并将其设置为已禁用 。 VM重启后,应该解决了。 Access [Start menu] and in [search program and files] type Run. Inside [Run line] type gpedit.msc. There, go to ...
  • 要更改目录的权限,可以在mount语句中使用dmode和fmode参数: mount -t vboxsf -o rw,dmode=775,fmode=775 shared shared 您不需要指定uid和gid,但需要将apache用户添加到vboxsf组: usermod -G vboxsf apache 最后,实际使它工作的是你需要禁用selinux。 现在,我可以在Windows中查看/编辑我的文件,让VM在浏览器中为它们提供服务。 这样做的目的是能够在Windows上开发,但让我的Web应用程 ...

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)