编码常用的一些函数如获取ip发送邮件curl封装加解密字符串对象转数组后面会有补充 无 //获取ipfunction ip(){if(getenv('x-forwarded-for')strcasecmp(getenv('x-forwarded-for'), 'unknown')){$ip = getenv('x-forwarded-for');}elseif(getenv('http_client_
编码常用的一些函数 如获取ip 发送邮件 curl封装 加解密字符串 对象转数组 后面会有补充 //获取ipfunction ip(){ if(getenv('x-forwarded-for')&&strcasecmp(getenv('x-forwarded-for'), 'unknown')) { $ip = getenv('x-forwarded-for'); } elseif(getenv('http_client_ip')&&strcasecmp(getenv('http_client_ip'), 'unknown')) { $ip = getenv('http_client_ip'); } elseif(getenv('http_x_forwarded_for')&&strcasecmp(getenv('http_x_forwarded_for'), 'unknown')) { $ip = getenv('http_x_forwarded_for'); } elseif(getenv('remote_addr')&&strcasecmp(getenv('remote_addr'), 'unknown')) { $ip = getenv('remote_addr'); } elseif(isset($_server['remote_addr'])&&$_server['remote_addr']&&strcasecmp($_server['remote_addr'], 'unknown')) { $ip = $_server['remote_addr']; } return preg_match(/[\d\.]{7,15}/, $ip, $matches) ? $matches[0] : 'unknown';}//curl封装function curl($url, $method = 'get', $postfields = null, $header = null){ $ch = curl_init(); curl_setopt($ch, curlopt_http_version, curl_http_version_1_0); curl_setopt($ch, curlopt_failonerror, false); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_timeout, 5); if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == https) { curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, false); } switch ($method) { case 'post': curl_setopt($ch, curlopt_post, true); if (!empty($postfields)) { if (is_array($postfields) || is_object($postfields)) { if (is_object($postfields)) $postfields = bin_tools::object2array($postfields); $postbodystring = ; $postmultipart = false; foreach ($postfields as $k => $v) { if (@ != substr($v, 0, 1)) { //判断是不是文件上传 $postbodystring .= $k= . urlencode($v) . &; } else { //文件上传用multipart/form-data,否则用www-form-urlencoded $postmultipart = true; } } unset($k, $v); if ($postmultipart) { curl_setopt($ch, curlopt_postfields, $postfields); } else { curl_setopt($ch, curlopt_postfields, substr($postbodystring, 0, -1)); } } else { curl_setopt($ch, curlopt_postfields, $postfields); } } break; default: if (!empty($postfields) && is_array($postfields)) $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($postfields); break; } curl_setopt($ch, curlopt_url, $url); if (!empty($header) && is_array($header)) { curl_setopt($ch, curlopt_httpheader, $header); } $response = curl_exec($ch); if (curl_errno($ch)) { throw new exception(curl_error($ch), 0); } curl_close($ch); return $response;}//对象转数组function object_to_array($obj){ $_arr = is_object($obj) ? get_object_vars($obj) : $obj; foreach ($_arr as $key => $val) { $val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val; $arr[$key] = $val; } return $arr;}//发送邮件 基于phpmailerfunction sendmail($to, $title, $content){ $mail = new lib_phpmail_phpmail(); $mail->charset =utf-8; $mail->issmtp(); $mail->smtpauth = true; $mail->smtpsecure = ssl; $mail->host = 11.111.11.11:465; $mail->port = 25; $mail->username = aaa@aaa.com; $mail->password = 123abc; $mail->setfrom('aaa@aaa.com', 'info'); $mail->addaddress($to); $mail->ishtml(true); $mail->subject = $title; $mail->body = $content; return $mail->send();}//加密字符串function encrypt($encrypt,$key=key) { $iv = mcrypt_create_iv ( mcrypt_get_iv_size ( mcrypt_rijndael_256, mcrypt_mode_ecb ), mcrypt_rand ); $passcrypt = mcrypt_encrypt ( mcrypt_rijndael_256, $key, $encrypt, mcrypt_mode_ecb, $iv ); $encode = base64_encode ( $passcrypt ); return $encode;}//解密字符串function decrypt($decrypt,$key=key) { $decoded = base64_decode ( $decrypt ); $iv = mcrypt_create_iv ( mcrypt_get_iv_size ( mcrypt_rijndael_256, mcrypt_mode_ecb ), mcrypt_rand ); $decrypted = mcrypt_decrypt ( mcrypt_rijndael_256, $key, $decoded, mcrypt_mode_ecb, $iv ); return $decrypted;}//分页 function getpage($count, $pagenum, $pagesize, $linksize = 10) { if($count == 0) return ''; $totalpage = ceil($count/$pagesize); $p = 'page'; $request_url = $_server['request_uri']; if(strpos($request_url,'?')) { $url = $request_url; } else { $url = $request_url.'?'; } $parse = parse_url($url); if(isset($parse['query'])) { parse_str($parse['query'],$params); unset($params[$p]); $url = $parse['path'].'?'.http_build_query($params); } //首页 尾页 if($pagenum > 1) { $firstpage = '首页 '; } if($pagenum 0) { $uppage='上一页'; } if ($downrow = 0x800 && $unicode_c_val > 12 | $h; $c2 = (($unicode_c_val & 0xfc0) >> 6) | $f; $c3 = ($unicode_c_val & 0x3f) | $f; $str=chr($c1).chr($c2).chr($c3); } //u-00010000 - u-001fffff: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx else if($unicode_c_val >= 0x10000 && $unicode_c_val > 18 | $h; $c2 = (($unicode_c_val & 0x3f000) >>12) | $f; $c3 = (($unicode_c_val & 0xfc0) >>6) | $f; $c4 = ($unicode_c_val & 0x3f) | $f; $str = chr($c1).chr($c2).chr($c3).chr($c4); } //u-00200000 - u-03ffffff: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx else if($unicode_c_val >= 0x200000 && $unicode_c_val > 24 | $h; $c2 = (($unicode_c_val & 0xfc0000)>>18) | $f; $c3 = (($unicode_c_val & 0x3f000) >>12) | $f; $c4 = (($unicode_c_val & 0xfc0) >>6) | $f; $c5 = ($unicode_c_val & 0x3f) | $f; $str = chr($c1).chr($c2).chr($c3).chr($c4).chr($c5); } //u-04000000 - u-7fffffff: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx else if($unicode_c_val >= 0x4000000 && $unicode_c_val > 30 | $h; $c2 = (($unicode_c_val & 0x3f000000)>>24) | $f; $c3 = (($unicode_c_val & 0xfc0000)>>18) | $f; $c4 = (($unicode_c_val & 0x3f000) >>12) | $f; $c5 = (($unicode_c_val & 0xfc0) >>6) | $f; $c6 = ($unicode_c_val & 0x3f) | $f; $str = chr($c1).chr($c2).chr($c3).chr($c4).chr($c5).chr($c6); } return $str; }, $unicode_c); return $unicode_c; }