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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
H
Help Net Security
V
Visual Studio Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
The Cloudflare Blog
Martin Fowler
Martin Fowler
D
Docker
腾讯CDC
F
Fortinet All Blogs
雷峰网
雷峰网
GbyAI
GbyAI
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
博客园 - 叶小钗

博客园 - 涂文瀚

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