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

推荐订阅源

Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
IT之家
IT之家
J
Java Code Geeks
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
量子位
I
InfoQ
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
V
V2EX
博客园 - Franky
U
Unit 42
S
SegmentFault 最新的问题
美团技术团队
The Register - Security
The Register - Security
Last Week in AI
Last Week in AI
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
M
MIT News - Artificial intelligence
博客园 - 聂微东
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Troy Hunt's Blog
B
Blog
P
Palo Alto Networks Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
K
Kaspersky official blog
The GitHub Blog
The GitHub Blog
C
Cisco Blogs
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
S
Schneier on Security
C
CERT Recently Published Vulnerability Notes
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
小众软件
小众软件
T
Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Martin Fowler
Martin Fowler
AWS News Blog
AWS News Blog
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
H
Heimdal Security Blog

博客园 - 涂文瀚

常用的前端调试工具 用户中心 - 博客园 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']) . '!';
?>