惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Threatpost
NISL@THU
NISL@THU
A
Arctic Wolf
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Tenable Blog
O
OpenAI News
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog
Cloudbric
Cloudbric
PCI Perspectives
PCI Perspectives
爱范儿
爱范儿
GbyAI
GbyAI
U
Unit 42
IT之家
IT之家
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
罗磊的独立博客
Last Week in AI
Last Week in AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
AWS News Blog
AWS News Blog
Schneier on Security
Schneier on Security
L
LINUX DO - 最新话题
Latest news
Latest news
Hacker News: Ask HN
Hacker News: Ask HN
W
WeLiveSecurity
TaoSecurity Blog
TaoSecurity Blog
Attack and Defense Labs
Attack and Defense Labs
Scott Helme
Scott Helme
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Securelist
Help Net Security
Help Net Security
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX
S
Security @ Cisco Blogs
月光博客
月光博客
P
Proofpoint News Feed
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog
博客园 - 叶小钗
C
Check Point Blog
腾讯CDC
The Cloudflare Blog
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 涂文瀚

常用的前端调试工具 用户中心 - 博客园 SQL中动态进行行转列 SQL SERVER 表分区实施步奏 [记录]SQL SERVER 跨库操作小记 PHP常见面试问题 在WIN下搭建PHP的测试、开发环境 [转]三款免费的PHP加速器:APC eAccelerator XCache比较 Xdebug如何选择PHP版本 PHP Cookbook读书笔记 – 第01章字符串 PHP Cookbook读书笔记 – 第03章日期和时间 PHP Cookbook读书笔记 – 第02章数字 PHP Cookbook读书笔记 – 第04章数组 PHP Cookbook读书笔记 – 第06章函数 PHP Cookbook读书笔记 – 第07章类和对象 PHP Cookbook读书笔记 – 第08章web基础 设计模式之观察者模式 PHP Cookbook读书笔记 – 第11章Session和持久化 PHP Cookbook读书笔记 – 第12章XML
PHP Cookbook读书笔记 – 第09章表单
涂文瀚 · 2011-12-13 · via 博客园 - 涂文瀚

本章的内容可以说是上一章节的延续,因为表单也是web的基础,但同时也是web基础中的重要组成部分。本章重点介绍了表单中可能出现的各项表单元素的验证、文件上传以及相关的安全问题。

$_SERVER['REQUEST_METHOD']:检测请求是GET还是POST

验证email地址是否有效的函数:

 
function is_valid_email_address($email){ 
        $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; 
        $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; 
        $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'. 
            '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; 
        $quoted_pair = '\\x5c[\\x00-\\x7f]'; 
        $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d"; 
        $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22"; 
        $domain_ref = $atom; 
        $sub_domain = "($domain_ref|$domain_literal)"; 
        $word = "($atom|$quoted_string)"; 
        $domain = "$sub_domain(\\x2e$sub_domain)*"; 
        $local_part = "$word(\\x2e$word)*"; 
        $addr_spec = "$local_part\\x40$domain"; 
        return preg_match("!^$addr_spec$!", $email) ? 1 : 0; 
} 

if (is_valid_email_address('cal@example.com')) { 
   print 'cal@example.com is a valid e-mail address'; 
} else { 
   print 'cal@example.com is not a valid e-mail address'; 
}

PHP中的超级变量

$_SERVER:服务器和运行环境的相关信息

$_GET:HTTP的GET请求变量

$_POST:POST变量,对于多选的Checkbox是一个数组

$_FILES:文件上传变量

$_REQUEST:一个数组,包含了GET、POST、COOKIE

$_SESSION:Session变量

$_ENV:环境变量

$_COOKIE:cookie变量

htmlentities()htmlspecialchars()的区别:htmlspecialchars只转化(&’”<>)这5个字符,而

htmlentities将会转换所有内容

PHP多选的处理代码

 The Bronx
 Brooklyn
 Manhattan
 Queens
 Staten Island

<?php
print 'I love ' . join(' and ', $_POST['boroughs']) . '!';
?>