Heim  >  Artikel  >  php教程  >  PHP Cookbook读书笔记 – 第09章表单

PHP Cookbook读书笔记 – 第09章表单

WBOY
WBOYOriginal
2016-06-06 19:40:481068Durchsuche

本章的内容可以说是上一章节的延续,因为表单也是web的基础,但同时也是web基础中的重要组成部分。本章重点介绍了表单中可能出现的各项表单元素的验证、文件上传以及相关的安全问题。 $_SERVER['REQUEST_METHOD']:检测请求是GET还是POST 验证email地址是否

PHP Cookbook读书笔记 – 第09章表单本章的内容可以说是上一章节的延续,因为表单也是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']) . '!';
?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn