if(!preg_match('/^[a-zA-Z0-9_*]{6,10}$/',$pwd)){ echo "<script>alert('密码必填,且只能大小写字符和数字,以及*、_构成,长度为6到10个字符!');history.back();</script>"; exit; }
时间: 2023-05-25 20:02:48 浏览: 47
This code is a PHP script that checks if a password (represented by the variable $pwd) meets certain criteria:
1. It must consist only of letters (both uppercase and lowercase), numbers, asterisks (*) and underscores (_).
2. It must be between 6 and 10 characters long.
If the password does not meet these criteria, the script displays an alert box with an error message stating the requirements and goes back to the previous page using the history.back() method. The exit() function is used to terminate the script execution.
相关问题
<?php show_source(__FILE__); $mess=$_POST['mess']; if(preg_match("/[a-zA-Z]/",$mess)){ die("invalid input!"); } eval($mess);
这是一个非常危险的代码,它将用户输入的数据直接传给 eval 函数,这意味着用户可以在服务器上执行任意的 PHP 代码。此外,该代码还使用了不安全的 preg_match 函数来检查用户输入是否包含字母,这可以轻松地被绕过。攻击者可以利用此漏洞执行恶意代码,例如删除服务器上的文件,创建新的文件,修改数据库等等。
如果您正在使用此代码,请立即停止并修改代码以避免安全漏洞。建议使用 PHP 的过滤器函数或第三方库来验证和过滤用户输入,而不是直接传递给 eval 函数。
if(strlen($code) > 70 or preg_match('/[A-Za-z0-9]|\'|"|`|\ |,|\.|-|\+|=|\/|\\|<|>|\$|\?|\^|&|\|/ixm',$code))
这段代码是一个PHP代码段,主要是用于判断变量$code的长度是否大于70或者是否包含特定的字符。其中preg_match()函数用于匹配正则表达式,如果匹配成功则返回1,否则返回0。正则表达式中包含了多个特殊字符,例如单引号、双引号、反引号、空格、逗号、句号、减号、加号、等号、斜杠、反杠、小于号、大于号、美元符号、问号、脱字符和竖线。如果$code的长度大于70或者包含了上述任意一个特殊字符,则条件成立。
演示代码如下:
```php
$code = "This is a test code.";
if(strlen($code) > 70 or preg_match('/[A-Za-z0-9]|\'|"|`|\ |,|\.|-|\+|=|\/|\\|<|>|\$|\?|\^|&|\|/ixm',$code)){
echo "Code is invalid.";
} else {
echo "Code is valid.";
}
```