English 中文(简体)
当我人工将价值分配到_POST阵列时,为什么会过滤NNUL的回报?
原标题:why does filter_input() return NULL when I manually assign value to $_POST array?

I m following some exercises about data validation and decided to mess around with the filter_input() function. When I try to run this code:

$_POST[ var ] = 10;

$filtered = filter_input(INPUT_POST,  var , FILTER_VALIDATE_FLOAT);

var_dump($filtered);

var_dump(过滤费用) Return NUL. 我知道,如果通过提交表格来分配<代码>_$_POST[ var]的价值,那么I m只是想知道,为什么人工将价值分配到<代码>_POST[]上?

最佳回答

filter_input(>.n t宣读了_POST/_GET/_COOKIE/_SERVER/_ENV超级全球阵列。 它分别从这些价值观的原始来源(这些来源也用来为超级全球化人口居住)。

问题回答

This is because INPUT_POST works on the original POST values, modifications to them in your script have no effect. However, if you want to filter that var you can use:

filter_var($_POST[ var ], FILTER_VALIDATE_FLOAT);

如果你想要设定默认输入值和过滤器,则使用<代码>filter_var。 由于过滤-投入,t 过滤了超级全球化的现值。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签