取得隨機字串
-
/*
- 作用:取得隨機字串
- 參數:
- 1、(int)$length = 32 #隨機字元長度,預設為32
- 2、(int)$mode = 0 #隨機字元類型,0為大小寫英文和數字,1為數字,2為小寫子木,3為大寫字母,4為大小寫字母, 5為大寫字母和數字,6為小寫字母和數字
- 傳回:取得的字串
- 使用:
- $code = new activeCodeObj;
- $str = $code->getCode($length , $mode);
- */
- class activeCodeObj
- {
- function getCode ($length = 32, $mode = 0)
- {
- switch ($mode) {
- case '1':
- $str = '1234567890';
- break;
- case '2':
- $str = 'abcdefghijklmnopqrstuvwxyz';
- break = 'abcdefghijklmnopqrstuvwxyz';
- break;$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- break;
- case '4':
- $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefijklmnoprbreak; >$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
- break;
- case '6':
- $str = 'abcdefghijklmnopqrstuvwxyz1234567890'>g; OPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890' ;
- break;
- }
-
- $result = '';
- $l = strlen($str);
-
- for($i = 0;$i $num = rand(0, $l);
- $result .= $str[$num];
- }
- return $result;
- }
- }
- 取得客戶端資訊
-
- /*
- 作用:取得客戶端資訊
- 參數:
- 回傳:指定的資料
- 使用:
- 參數:
- 回傳:指定的資料
- 使用:
- 參數:
- 回傳:指定的資料
- 使用:
- 參數:
- 回傳:指定的資料
- 使用:
- $code = new clientGetObj;
- 1、瀏覽器:$str = $code->getBrowse();
- 2、IP位址:$str = $code->getIP();
- 4、作業系統:$str = $code->getOS();
- */
-
- class clientGetObj
- {
- function getBrowse()
- {glo $function getBrowse()
- {glo $_SERVER 🎜>$Agent = $_SERVER['HTTP_USER_AGENT'];
- $browser = '';
- $browserver = '';
- $Browser = array('Lynx', 'MOSAIC', 'AOL' , 'Opera', 'JAVA', 'MacWeb', 'WebExplorer', 'OmniWeb');
- for($i = 0; $i if(strpos ($Agent, $Browsers[$i])){
- $browser = $Browsers[$i];
- $browserver = '';
- }
- }
- if(ereg( 'Mozilla', $Agent) && !ereg('MSIE', $Agent)){
- $temp = explode('(', $Agent);
- $Part = $temp[0];
- $temp = explode('/', $Part);
- $browserver = $temp[1];
- $temp = explode(' ', $browserver);
- $browserver = $temp[ 0];
- $browserver = preg_replace('/([d.]+)/', '1', $browserver);
- $browserver = $browserver;
- $browser = 'Netscape Navigator' ;
- }
- if(ereg('Mozilla', $Agent) && ereg('Opera', $Agent)) {
- $temp = explode('(', $Agent);
- $Part = $temp[1];
- $temp = explode(')', $Part);
- $browserver = $temp[1];
- $temp = explode(' ', $browserver );
- $browserver = $temp[2];
- $browserver = preg_replace('/([d.]+)/', '1', $browserver);
- $browserver = $browserver ;
- $browser = 'Opera';
- }
- if(ereg('Mozilla', $Agent) && ereg('MSIE', $Agent)){
- $temp = explode(' (', $Agent);
- $Part = $temp[1];
- $temp = explode(';', $Part);
- $Part = $temp[1];
- $temp = explode(' ', $Part);
- $browserver = $temp[2];
- $browserver = preg_replace('/([d.]+)/','1',$browserver );
- $browserver = $browserver;
- $browser = 'Internet Explorer';
- }
- if($browser != ''){
- $browseinfo = $browser.' ' .$browserver;
- } else {
- $browseinfo = false;
- }
- return $browseinfo;
- }
-
- function getIP ()
- }
-
- function getIP ()
- > global $_SERVER;
- if (getenv('HTTP_CLIENT_IP')) {
- $ip = getenv('HTTP_CLIENT_IP');
- } else if (getenv('HTTP_X_IP');
- } else if (getenv('HTTP_X_FORWARDED_FOR'))> = getenv('HTTP_X_FORWARDED_FOR');
- } else if (getenv('REMOTE_ADDR')) {
- $ip = getenv('REMOTE_ADDR');
- } else {
- ['REMOTE_ADDR'];
- }
- return $ip;
- }
-
- function getOS ()
- {
- global $_SERVER;$os = false;
- if (eregi('win', $agent) && strpos($agent, '95')){
- $os = 'Windows 95' ;
- }
- else if (eregi('win 9x', $agent) && strpos($agent, '4.90')){
- $os = 'Windows ME';
- }
- else if (eregi('win', $agent) && ereg('98', $agent)){
- $os = 'Windows 98';
- }
- else if (eregi('win ', $agent) && eregi('nt 5.1', $agent)){
- $os = 'Windows XP';
- }
- else if (eregi('win', $agent) && eregi ('nt 5', $agent)){
- $os = 'Windows 2000';
- }
- else if (eregi('win', $agent) && eregi('nt', $agent )){
- $os = 'Windows NT';
- }
- else if (eregi('win', $agent) && ereg('32', $agent)){
- $os = 'Windows 32';
- }
- else if (eregi('linux', $agent)){
- $os = 'Linux';
- }
- else if (eregi(' unix', $agent)){
- $os = 'Unix';
- }
- else if (eregi('sun', $agent) && eregi('os', $agent)){
- $os = 'SunOS';
- }
- else if (eregi('ibm', $agent) && eregi('os', $agent)){
- $os = 'IBM OS/ 2';
- }else if (eregi('Mac', $agent) && eregi('PC', $agent)){$os = 'Macintosh';}
- else if (eregi('PowerPC', $agent)){
- $os = 'PowerPC';
- }
- else if (eregi('AIX', $agent)){
- $os = 'AIX';
- }
- else if (eregi('HPUX', $agent)){
- $os = 'HPUX';
- }
- else if (eregi ('NetBSD', $agent)){
- $os = 'NetBSD';
- }
- else if (eregi('BSD', $agent)){
- $os = 'BSD' ;
- }
- else if (ereg('OSF1', $agent)){
- $os = 'OSF1';
- }
- else if (ereg('IRIX', $agent ) ) )){
- $os = 'IRIX';
- }
- else if (eregi('FreeBSD', $agent)){
- $os = 'FreeBSD';
- }
- else if (eregi('teleport', $agent)){
- $os = 'teleport';
- }
- else if (eregi('flashget', $agent)){
- $ os = 'flashget';
- }
- else if (eregi('webzip', $agent)){
- $os = 'webzip';
- }
- else if (eregi ( '離線', $agent)){
- $os = '離線';
- }
- else {
- $os = '未知';
- }
- 回傳$os;
- }
-
- }
-
- //修改自q3boy
- class cnStrObj
- {
- function substrGB ($str = '', $start = '', $start = '', $start = '' len = ''){
- if($start == 0 || $start == ''){
- $start = 1;
- }
- if($str == '' | | $ len == ''){
- 回傳false;
- }
- for($i = 0; $i $tmpstr = (奧德($str[$i]) >= 161 && 奧德($str[$i]) = 161 && 奧德($str[ $i]) + 1]) if ($i >= $start && $我{
- $tmp .=$tmpstr;
- }
- }
- 回傳$tmp;
- }
-
- 函數isGB ( $ str)
- {
- $strLen = strlen($str);
- $length = 1;
- for($i = 0; $i $tmpstr = ord(substr($str, $i, 1));
- $tmpstr2 = ord(substr($str, $i+1, 1));
- if(($tmpstr = 247) && ($tmpstr2 = 247)){
- $legalflag = false;
- } else {
- $ legalflag = true;
- }
- }
- return $legalflag;
- }
- }
-
- //下載自某網站
- /**
-
- //下載自某網站
- /** */
-
- define('SMTP_STATUS_NOT_CONNECTED', 1, TRUE);
- define('SMTP_STATUS_CONNECTED', 2, TRUE);
-
- class smh{
- $ $ $var $recipients;
- var $headers;
- var $timeout;
- var $errors;
- var $status;
- var $body;
- var $from ;
- var $host;
- var $port;
- var $helo;
- var $auth;
- var $user;
- var $pass;
-
- / ***************************************
- ** 檔案名稱...... : class.smtp.inc
- ** 項目........: SMTP 類別
- ** 版本........: 1.00b
- ** 最後修改..: 2001 年9 月30 日
- ***************************************** ****/
-
- function smtp($params = array()){
-
- if(!define('CRLF'))
- define('CRLF', " rn", TRUE);
-
- $this->超時= 5;
- $this->status = SMTP_STATUS_NOT_CONNECTED;
- $this->host = 'localhost';
- $this--this-->host- >port = 25;
- $this->helo = 'localhost';
- $this->auth = FALSE;
- $this->user = '';
- $this->pass = '';
- $this->errors = array();
-
- foreach($params as $key =>; $value){
- $this->$key = $value;
- }
- }
-
- /****************************************
- ** 建構子。參數:
- ** $params - 參數的關聯數組:
- **
- ** host - smtp 伺服器的主機名稱預設值:localhost
- ** port - smtp 伺服器執行的連接埠預設值:25
- ** helo - 作為HELO 命令發送的內容預設值:localhost
- ** (通常是此腳本運行的
- ** 機器的主機名稱)
- ** auth -是否使用基本驗證預設:FALSE
- ** user - 驗證的使用者名稱預設:
- ** pass - 驗證的密碼預設:
- ** timeout - 逾時時間呼叫秒數預設:5
- ** 到fsockopen()
- ************************************** ** *****/
-
- 函數連接($ params = array()){
-
- if(!isset($這個->狀態)){
- $obj = new smtp($params);
- if($obj->; connect()){
- $obj->status = SMTP_STATUS_CONNECTED;
- }
-
- return $obj;
-
- }else{
- $this-open>連接$this->主機, $this->連接埠, $errno, $errstr, $this->逾時);
- socket_set_timeout($this->連線, 0, 250000);
-
- $greeting = $this->get_data();
- if(is_resource($this->connection)){
- 回傳$this->auth ? $this->ehlo() : $this->helo();
- }else{
- $this->errors[] = ' 無法連線到伺服器: '.$errstr;
- 回傳FALSE;
- }
- }
- }
-
- /****************************************
- ** 處理發送郵件的函數。
- ** 參數:
- ** $params - 可選的關聯參數陣列。
- ** 可以包含:
- **收件者 - 收件者索引陣列
- ** from - 寄件者位址。 (在MAIL FROM 中使用,
- ** 這將是返迴路徑
- ** 標頭- 索引數組標頭,每個陣列項目一個標頭
- ** 正文- 電子郵件正文
- ** 它也可以包含connect()
- ** 函數
- *** 中的任何參數** *************************************/
-
- function send($params = array()){
-
- foreach($params as $key => $value) {
- $this->set($key, $value);
- }
-
- if($this->is_connected()){
-
- // 我們做是否授權注意auth 變數與auth() 函數的差異
- if($this->auth){
- if(!$this->auth())
- return FALSE;
- }
-
- $this->mail($this->from);
- if(is_array($this->recipients))
- foreach($this->recipients as $value )
- $ this- >rcpt($value);
- else
- $this->rcpt($this->函數);
-
- if(!$this-> ;data())
- return FALSE ;
-
- // 透明度
- $headers = str_replace(CRLF.'.', CRLF.'..', trim(implode(CRLF, $this-> headers)));
- $ body = str_replace(CRLF.'.', CRLF.'..', $this->body);
- $body = $body[0] == ' .' '.'.$body : $body;
-
- $this->send_data($headers);
- $this->send_data('');
- $this->send_data ($ body );
- $this->send_data('.');
-
- return (substr(trim($this->get_data()), 0, 3) === ' 250');
- }else{
- $this->errors[] = '未連接!
-
- 函數helo(){
- if(is_resource($this->connection)
- AND $this->send_data('HELO '.$this-> ;helo)
- AND substr (trim($error = $this->get_data()), 0, 3) === '250' ){
-
- 回傳TRUE;
-
- }else{
- $ this ->errors[] = 'HELO指令失敗,輸出:' . rim(substr(trim($error),3));
- return FALSE;
- }
- }
-
- /****************************************
- ** 實作HELO cmd 的函數
- *******************************************/
-
- 函數嘿嘿(){
- if(is_resource($this->connection)
- AND $this->send_data('EHLO '.$this->helo)
- AND substr(trim($error = $this- >get_data()), 0, 3) === '250' ){
-
- 回傳TRUE;
-
- }else{
- $this->errors[ ] = 'EHLO 指令失敗,輸出:' . rim(substr(trim($error),3));
- 回傳 FALSE;
- }
- }
-
- /****************************************
- ** 實作EHLO cmd 的函數
- *******************************************/
-
- 函數驗證(){
- if(is_resource($this->connection)
- AND $this->send_data('AUTH LOGIN')
- AND substr(trim($error = $this->get_data) () ), 0, 3) === '334'
- AND $this->send_data(base64_encode($this->user)) // 傳送使用者名稱
- AND substr(trim($error = $this- >get_data()),0,3) === '334'
- AND $this->send_data(base64_encode($this->pass)) // 傳送密碼
- AND substr (trim($error = $this->get_data()),0,3) === '235' ){
-
- 回傳TRUE;
-
- }else{
- $ this->errors[] = 'AUTH 指令失敗:' 。 rim(substr(trim($error),3));
- return FALSE;
- }
- }
-
- /****************************************
- ** 實作AUTH cmd 的函數
- *******************************************/
-
- 函數郵件($from){
-
- if($this->is_connected()
- AND $this->send_data('MAIL FROM:' )
- AND substr(trim($this->get_data()), 0, 2) === '250' ){
-
- 回傳TRUE;
-
- }else
- 回傳FALSE ;
- }
-
- /****************************************
- ** 處理MAIL FROM 的函數:cmd
- *****************************************/
-
- 函數rcpt($to){
-
- if($this->is_connected()
- AND $this->send_data('RCPT TO:')
- AND substr(trim($error = $this->get_data()), 0, 2) === '25' ){
-
- 返回TRUE;
-
- }else{
- $this->errors[] = trim(substr(trim($error), 3) );
- 回傳FALSE;
- }
- }
-
- /***************************************
- ** 處理RCPT TO 的函數:cmd
- *****************************************/
-
- 函數data(){
-
- if($ this->is_connected){
-
- if($ this->is_connected ()
- AND $this->send_data('DATA')
- AND substr(trim($error = $this->get_data()), 0, 3) === '354' ){
-
- 回傳TRUE;
-
- }else{
- $this->errors[] = trim(substr(trim($error), 3));
- 回傳FALSE;
- }
- }
-
- /****************************************
- ** 判斷此物件是否** 是否連接到伺服器。
- **************************************** ***/
-
- function is_connected(){
-
- return (is_resource($this->connection) AND ($this->status == = SMTP_STATUS_CONNECTED));
- }
-
- /****************************************
- ** 發送一點資料的函數
- *********************************************/
-
- 函數send_data($data){
-
- if(is_resource($this ->連接)){
- return fwrite($this->connection, $data.CRLF, strlen($data)+2);
- }else
- return FALSE;
- }
-
- /****************************************
- ** 取得資料的函數。
- *******************************************/
-
- 函數&get_data(){
-
- $return = '';
- $line = '';
-
- if(is_resource ($this->connection)){
- while(strpos($return, CRLF) === FALSE OR substr($line,3,1) !== ' '){
- $line = fgets( $this->連線, 512);
- $return .= $line;
- }
- 回傳$return;
-
- }else
- 回傳FALSE;
- }
-
- /****************************************
- ** 設定變數
- ** ***************************************/
-
- 函數集($var, $value){
-
- $this->$var = $value ;
- 返回TRUE;
- }
-
- } // 課程結束
- ?>
-
複製代碼
|