比如我写好的POST提交例子,验证邮箱和值是否未空?
<code>include("check.php"); $check = new VerifyAction(); if(?){ echo '提交成功!'; }else{ echo '填写不对 重填写'; } <form action="index.php" method="post"> <input type="text" name="name"><br> <input type="text" name="email"><br> <input type="submit"> </form> </code>
验证类 check.php
<code><?php /** * 验证类 * * @lastmodify 2014-5-16 * @author jy625 */ class VerifyAction{ /** * 是否为空值 */ public static function isEmpty($str){ $str = trim($str); return !empty($str) ? true : false; } /** * 数字验证 * param:$flag : int是否是整数,float是否是浮点型 */ public static function isNum($str,$flag = 'float'){ if(!self::isEmpty($str)) return false; if(strtolower($flag) == 'int'){ return ((string)(int)$str === (string)$str) ? true : false; }else{ return ((string)(float)$str === (string)$str) ? true : false; } } /** * 名称匹配,如用户名,目录名等 * @param:string $str 要匹配的字符串 * @param:$chinese 是否支持中文,默认支持,如果是匹配文件名,建议关闭此项(false) * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isName($str,$chinese = true,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; if($chinese){ $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_-]+$/" : "/^[x{4e00}-x{9fa5}A-Za-z0-9_]+$/u"; }else{ $match = '/^[A-za-z0-9_-]+$/'; } return preg_match($match,$str) ? true : false; } /** * 邮箱验证 */ public static function isEmail($str){ if(!self::isEmpty($str)) return false; return preg_match("/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i",$str) ? true : false; } //手机号码验证 public static function isMobile($str){ $exp = "/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{8}$|14[57]{1}[0-9]$/"; if(preg_match($exp,$str)){ return true; }else{ return false; } } /** * URL验证,纯网址格式,不支持IP验证 */ public static function isUrl($str){ if(!self::isEmpty($str)) return false; return preg_match('#(http|https|ftp|ftps)://([w-]+.)+[w-]+(/[w-./?%&=]*)?#i',$str) ? true : false; } /** * 验证中文 * @param:string $str 要匹配的字符串 * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isChinese($str,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."]+$/" : "/^[x{4e00}-x{9fa5}]+$/u"; return preg_match($match,$str) ? true : false; } /** * UTF-8验证 */ public static function isUtf8($str){ if(!self::isEmpty($str)) return false; return (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true) ? true : false; } /** * 验证长度 * @param: string $str * @param: int $type(方式,默认min <= $str <= max) * @param: int $min,最小值;$max,最大值; * @param: string $charset 字符 */ public static function length($str,$type=3,$min=0,$max=0,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; $len = mb_strlen($str,$charset); switch($type){ case 1: //只匹配最小值 return ($len >= $min) ? true : false; break; case 2: //只匹配最大值 return ($max >= $len) ? true : false; break; default: //min = 1000 && $timeArr[0] = 0 && $dateArr[1] = 0 && $dateArr[2] = 0 && $timeArr[0] = 0 && $timeArr[1] = 0 && $timeArr[2] </code>
回复内容:
比如我写好的POST提交例子,验证邮箱和值是否未空?
<code>include("check.php"); $check = new VerifyAction(); if(?){ echo '提交成功!'; }else{ echo '填写不对 重填写'; } <form action="index.php" method="post"> <input type="text" name="name"><br> <input type="text" name="email"><br> <input type="submit"> </form> </code>
验证类 check.php
<code><?php /** * 验证类 * * @lastmodify 2014-5-16 * @author jy625 */ class VerifyAction{ /** * 是否为空值 */ public static function isEmpty($str){ $str = trim($str); return !empty($str) ? true : false; } /** * 数字验证 * param:$flag : int是否是整数,float是否是浮点型 */ public static function isNum($str,$flag = 'float'){ if(!self::isEmpty($str)) return false; if(strtolower($flag) == 'int'){ return ((string)(int)$str === (string)$str) ? true : false; }else{ return ((string)(float)$str === (string)$str) ? true : false; } } /** * 名称匹配,如用户名,目录名等 * @param:string $str 要匹配的字符串 * @param:$chinese 是否支持中文,默认支持,如果是匹配文件名,建议关闭此项(false) * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isName($str,$chinese = true,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; if($chinese){ $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_-]+$/" : "/^[x{4e00}-x{9fa5}A-Za-z0-9_]+$/u"; }else{ $match = '/^[A-za-z0-9_-]+$/'; } return preg_match($match,$str) ? true : false; } /** * 邮箱验证 */ public static function isEmail($str){ if(!self::isEmpty($str)) return false; return preg_match("/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i",$str) ? true : false; } //手机号码验证 public static function isMobile($str){ $exp = "/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{8}$|14[57]{1}[0-9]$/"; if(preg_match($exp,$str)){ return true; }else{ return false; } } /** * URL验证,纯网址格式,不支持IP验证 */ public static function isUrl($str){ if(!self::isEmpty($str)) return false; return preg_match('#(http|https|ftp|ftps)://([w-]+.)+[w-]+(/[w-./?%&=]*)?#i',$str) ? true : false; } /** * 验证中文 * @param:string $str 要匹配的字符串 * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isChinese($str,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."]+$/" : "/^[x{4e00}-x{9fa5}]+$/u"; return preg_match($match,$str) ? true : false; } /** * UTF-8验证 */ public static function isUtf8($str){ if(!self::isEmpty($str)) return false; return (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true) ? true : false; } /** * 验证长度 * @param: string $str * @param: int $type(方式,默认min <= $str <= max) * @param: int $min,最小值;$max,最大值; * @param: string $charset 字符 */ public static function length($str,$type=3,$min=0,$max=0,$charset = 'utf-8'){ if(!self::isEmpty($str)) return false; $len = mb_strlen($str,$charset); switch($type){ case 1: //只匹配最小值 return ($len >= $min) ? true : false; break; case 2: //只匹配最大值 return ($max >= $len) ? true : false; break; default: //min = 1000 && $timeArr[0] = 0 && $dateArr[1] = 0 && $dateArr[2] = 0 && $timeArr[0] = 0 && $timeArr[1] = 0 && $timeArr[2] </code>
<code>include("check.php"); $check = new VerifyAction(); //验证邮箱 $check_email = $check->isEmail($_POST['email']); if($check_email) { //是正确的邮箱 }else{ //邮箱填写有问题... } </code>
不知道你明白了么?如果不明白 加群讨论下告诉你 群:231566327
<code>include("check.php"); if($_SERVER['REQUEST_METHOD']=='POST'){ if(!VerifyAction::isEmpty($_POST['name'])){ die("用户名不能为空") ; }elseif(!VerifyAction::isEmail($_POST['email'])){ die( "无效邮箱账号"); } echo "验证通过"; } </code>

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

Tracking user session activities in PHP is implemented through session management. 1) Use session_start() to start the session. 2) Store and access data through the $_SESSION array. 3) Call session_destroy() to end the session. Session tracking is used for user behavior analysis, security monitoring, and performance optimization.

Using databases to store PHP session data can improve performance and scalability. 1) Configure MySQL to store session data: Set up the session processor in php.ini or PHP code. 2) Implement custom session processor: define open, close, read, write and other functions to interact with the database. 3) Optimization and best practices: Use indexing, caching, data compression and distributed storage to improve performance.

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
