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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
S
Security @ Cisco Blogs
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
Microsoft Security Blog
Microsoft Security Blog
B
Blog
A
About on SuperTechFans
B
Blog RSS Feed
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
博客园 - Franky
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Palo Alto Networks Blog
罗磊的独立博客
S
Securelist
L
LINUX DO - 热门话题
T
Tor Project blog
人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
T
Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
Cyberwarzone
Cyberwarzone
NISL@THU
NISL@THU
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
G
Google Developers Blog
The Hacker News
The Hacker News
Latest news
Latest news
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
S
Schneier on Security

博客园 - 涂文瀚

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