php - How to preset $_POST for filter_input()?
问题描述
Assuming this script:
<?php $_POST['user'] = 'test'; ?>
<input type="text" name="user" value="<?php echo $_POST['user']; ?>">
<input type="text" name="user" value="<?php echo filter_input(INPUT_POST, 'user', FILTER_SANITIZE_SPECIAL_CHARS) ?>">
Why doesn't the second input see the $_POST value set on the first line and how can we make it see it?
解决方案
I'm looking for a reference as I have seen it in the past, but as you show, INPUT_POST
does not use the $_POST
superglobal array. At least not the at the state that you have access to. Since you are adding to $_POST
this won't work, you would need to use:
<?php echo filter_var($_POST['user'], FILTER_SANITIZE_SPECIAL_CHARS); ?>
推荐阅读
- python - 使用 Python 来“参与”Windows 的音频通道,类似于游戏或 youtube 视频,以避免在 7.1、5.1 等之间的不稳定切换
- c++ - 为什么我不应该将接口和实现放在一个文件中?
- django - 根据过滤的查询集有条件地在 Django admin 中显示列
- angular - 如何修复显示内存不足异常的 Ionic cordova 文档扫描仪
- ios - 我可以实时获取卡路里和步数以从 Watch 应用程序更新我的应用程序吗?
- amazon-cloudwatch - Cloudwatch 警报未将丢失数据视为未违反
- database - BigTable 聚合数据
- nginx - 如何在网站的子文件夹上托管烧瓶应用程序?
- firebase - Firestore 安全规则 - 当字段可能丢失时强制执行时间戳类型
- entity-framework-core - 如何在实体框架数据库中进行通用实体框架核心 OData 查询?