最近不是在折腾论坛嘛,各种类各种函数,原创一些,从别人那儿qiang过来一些,在此分享出来,希望有朋友能用的到~

注意:部分函数可能不够完善,由此造成的漏洞风险自担~

提交过滤

function filter($text)
{
 //完全过滤注释
 $text = preg_replace('/<!--"', $text);
 return $text;
}

提交过滤2

function stripslashes_array(&$array)
{
 while (list($key, $var) = each($array)) {
 if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || '' . intval($key) == "$key")) {
 if (is_string($var)) {
 $array[$key] = stripslashes($var);
 }
 if (is_array($var)) {
 $array[$key] = stripslashes_array($var);
 }
 }
 }
 return $array;
}

字符串截取(这个是emlog里提出来的,其实也就是substr的增强版)

function subString($strings, $start, $length)
{
 if (function_exists('mb_substr') && function_exists('mb_strlen')) {
 $sub_str = mb_substr($strings, $start, $length, 'utf8');
 return mb_strlen($sub_str, 'utf8') < mb_strlen($strings, 'utf8') "htmlcode">
function AnonymousIP() 
{
 $ip = GetIP();
 if ($ip == "Unknown") {
 $removed_ip = "未知用户";
 }
 if (strpos($ip, ":")) {
 $removed_ip = "IPv6用户";
 } else {
 $reg1 = '/(("\\1*", $ip);
 }
 return $removed_ip;
}

获取客户端IP地址

function GetIP()
{
 if (@$_SERVER["HTTP_X_FORWARDED_FOR"])
 $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
 else if (@$_SERVER["HTTP_CLIENT_IP"])
 $ip = $_SERVER["HTTP_CLIENT_IP"];
 else if (@$_SERVER["REMOTE_ADDR"])
 $ip = $_SERVER["REMOTE_ADDR"];
 else if (@getenv("HTTP_X_FORWARDED_FOR"))
 $ip = getenv("HTTP_X_FORWARDED_FOR");
 else if (@getenv("HTTP_CLIENT_IP"))
 $ip = getenv("HTTP_CLIENT_IP");
 else if (@getenv("REMOTE_ADDR"))
 $ip = getenv("REMOTE_ADDR");
 else
 $ip = "Unknown";
 return $ip;
}

字符串加密(支持中文)

function dencrypt($string, $isEncrypt = true, $key = "youdian")
{
 if (!isset($string{0}) || !isset($key{0})) {
 return false;
 }
 
 $dynKey = $isEncrypt "htmlcode">
function CheckChinese($string)
{
 if (preg_match("/[\x7f-\xff]/", $string)) {
 return true;
 } else {
 return false;
 }
}

隐藏文件真实路径

function FileHeaderJump($file)
{
 header('Content-Description: File Transfer');
 header('Content-Type: application/octet-stream');
 header('Content-Disposition: attachment; filename=' . basename($file));
 header('Content-Transfer-Encoding: binary');
 header('Expires: 0');
 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 header('Pragma: public');
 header('Content-Length: ' . filesize($file));
 ob_clean();
 flush();
 readfile($file);
 exit;
}

生成随机字符串,自定义长度

function CreateRandomString($length)
{
 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
 $password = "";
 for ($i = 0; $i < $length; $i++) {
 $password .= $chars[mt_rand(0, strlen($chars) - 1)];
 }
 return $password;
}

标签:
PHP,功能函数

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“分享自定义的几个PHP功能函数”

暂无“分享自定义的几个PHP功能函数”评论...