<?php
????? /*
????? ?*?? 生成指定數量和指定字符串生成隨機字符串
????? ?*?? @param int $len 獲取隨機字符的個數
????? ?*?? @param string $range 指定在該字符串中獲取隨機字符
????? */
????? function randomString($len,$range=''){
?????????? if($range == ''){
???????????????? $str = '0123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ';
?????????? }else{
???????????????? $str = $range;
?????????? }
?????????? $rand_str = '';
?????????? for($i=0;$i<$len;$i++){
???????????????? $rand_str .= $str[rand(0,strlen($str)-1)];
?????????? }
?????????? return $rand_str;
????? }
????? /*
????? ?* 遍歷文件夾
????? ?* @param string $path 路徑
????? */
????? function getListDir($path){//可嘗試添加按深度獲取
?????????? $file = array();
?????????? $dir = dir($path);
?????????? while($handle = $dir->read()){
???????????????? if($handle != '.' && $handle != '..'){
????????????????????? if(is_dir($dir->path.'\\'.$handle)){
??????????????????????????? $file[$handle] = getListDir($dir->path.'\\'.$handle);
????????????????????? }else{
??????????????????????????? $file[] = $handle;
????????????????????? }
???????????????? }
???????????????? $y++;
?????????? }
?????????? return $file;
????? }
????? /*
????? ?* 獲取用戶的ip地址????
????? */
????? function getIp(){
?????????? $ip = '';
?????????? if(isset($_SERVER['HTTP_CLIENT_IP'])){
???????????????? $ip = $_SERVER['HTTP_CLIENT_IP'];
?????????? }elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
???????????????? $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
?????????? }else{
???????????????? $ip = $_SERVER['REMOTE_ADDR'];
?????????? }
?????????? return $ip;
????? }
?
????? /*
????? ?* 取后綴的方法有很多,這只是其中一種
????? ?* @param string $filename 文件名
????? */
????? function getExt($filename){
?????????? $arr = explode('.',$filename);
?????????? $ext = $arr[count($arr)-1];
?????????? return $ext;
????? }
?
?
????? /*
????? ?* 記錄日志(這個和老版本的shopNc的記錄方式相同)
????? ?* @param string $txt 待寫入的日志內容
????? ?* @param string $base_path 存放日志文件的路徑
????? */
????? function log($txt,$base_path){
?????????? header("Content-type:text/html; charset=utf-8");
?????????? if(isset($base_path)){
???????????????? $path = $base_path;
?????????? }else{
???????????????? $path = dirname(__FILE__);
?????????? }
?????????? $filename = data("Y-m-d").'.log';
?????????? $filepath = $path.'\\'.$filename;
?????????? $content = data("Y-m-d H:i:s").':'.$txt.PHP_EOL;
?????????? if(file_put_contents($filepath,$content,FILE_APPEND)){
???????????????? return true;
?????????? }else{
???????????????? return false;
?????????? }
????? }
?????
???
?