Returns a random string.
- /*
- Purpose: obtain a random string.
- Parameters:
- 1. (int) $ length = 32 # random character length. the default value is 32.
- 2. (int) $ mode = 0 # random character type. 0 indicates uppercase and lowercase English letters and numbers, 1 indicates numbers, 2 indicates lowercase Wood, 3 indicates uppercase letters, and 4 indicates uppercase and lowercase letters, 5 is an uppercase letter and number, and 6 is a lowercase letter and number.
- Return: The obtained string.
- Usage:
- $ Code = new activeCodeObj;
- $ Str = $ code-> getCode ($ length, $ mode );
- */
- Class activeCodeObj
- {
- Function getCode ($ length = 32, $ mode = 0)
- {
- Switch ($ mode ){
- Case '1 ':
- $ Str = '000000 ';
- Break;
- Case '2 ':
- $ Str = 'abcdefghijklmnopqrstuvwxy ';
- Break;
- Case '3 ':
- $ Str = 'abcdefghijklmnopqrstuvwxy ';
- Break;
- Case '4 ':
- $ Str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy ';
- Break;
- Case '5 ':
- $ Str = 'abcdefghijklmnopqrstuvwxyz1234567890 ';
- Break;
- Case '6 ':
- $ Str = 'abcdefghijklmnopqrstuvwxyz1234567890 ';
- Break;
- Default:
- $ Str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234567890 ';
- Break;
- }
- $ Result = '';
- $ L = strlen ($ str );
- For ($ I = 0; $ I <$ length; $ I ++ ){
- $ Num = rand (0, $ l );
- $ Result. = $ str [$ num];
- }
- Return $ result;
- }
- }
- Obtain client information
- /*
- Role: obtain client information
- Parameters:
- Return: specified data
- Usage:
- $ Code = new clientGetObj;
- 1. browser: $ str = $ code-> getBrowse ();
- 2. IP address: $ str = $ code-> getIP ();
- 4. Operating system: $ str = $ code-> getOS ();
- */
- Class clientGetObj
- {
- Function getBrowse ()
- {
- Global $ _ SERVER;
- $ Agent = $ _ SERVER ['http _ USER_AGENT '];
- $ Browser = '';
- $ Browserver = '';
- $ Browser = array ('Lynx ', 'Mosaic', 'AOL ', 'Opera', 'Java', 'macweb', 'webexplorer ', 'omniweb ');
- For ($ I = 0; $ I <= 7; $ 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 ()
- {
- Global $ _ SERVER;
- If (getenv ('http _ CLIENT_IP ')){
- $ Ip = getenv ('http _ CLIENT_IP ');
- } Else if (getenv ('http _ X_FORWARDED_FOR ')){
- $ Ip = getenv ('http _ X_FORWARDED_FOR ');
- } Else if (getenv ('remote _ ADDR ')){
- $ Ip = getenv ('remote _ ADDR ');
- } Else {
- $ Ip = $ _ SERVER ['remote _ ADDR '];
- }
- Return $ ip;
- }
- Function getOS ()
- {
- Global $ _ SERVER;
- $ Agent = $ _ SERVER ['http _ USER_AGENT '];
- $ 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 ('netsd', $ agent )){
- $ OS = 'netsd ';
- }
- Else if (eregi ('bsd', $ agent )){
- $ OS = 'bsd ';
- }
- Else if (ereg ('oss1', $ agent )){
- $ OS = 'oss1 ';
- }
- 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 ('offline', $ agent )){
- $ OS = 'offline ';
- }
- Else {
- $ OS = 'unknown ';
- }
- Return $ OS;
- }
- }
- // Modify from q3boy
- Class cnStrObj
- {
- Function substrGB ($ str = '', $ start ='', $ len = ''){
- If ($ start = 0 | $ start = ''){
- $ Start = 1;
- }
- If ($ str = ''| $ len = ''){
- Return false;
- }
- For ($ I = 0; $ I <$ start + $ len; $ I ++ ){
- $ Tmpstr = (ord ($ str [$ I])> = 161 & ord ($ str [$ I]) <= 247 & ord ($ str [$ I + 1])> = 161 & ord ($ str [$ I + 1]) <= 254 )? $ Str [$ I]. $ str [++ $ I]: $ tmpstr = $ str [$ I];
- If ($ I >=$ start & $ I <($ start + $ len ))
- {
- $ Tmp. = $ tmpstr;
- }
- }
- Return $ tmp;
- }
- Function isGB ($ str)
- {
- $ StrLen = strlen ($ str );
- $ Length = 1;
- For ($ I = 0; $ I <$ strLen; $ I ++ ){
- $ Tmpstr = ord (substr ($ str, $ I, 1 ));
- $ Tmpstr2 = ord (substr ($ str, $ I + 1, 1 ));
- If ($ tmpstr <= 161 | $ tmpstr> = 247) & ($ tmpstr2 <= 161 | $ tmpstr2> = 247 )){
- $ Legalflag = false;
- } Else {
- $ Legalflag = true;
- }
- }
- Return $ legalflag;
- }
- }
- // Download from an e-file website
- /***************************************
- ** Filename...: class. smtp. inc
- ** Project ......: SMTP Class
- ** Version...: 1.00b
- ** Last Modified...: 30 September 2001
- ***************************************/
- Define ('smtp _ STATUS_NOT_CONNECTED ', 1, TRUE );
- Define ('smtp _ status_connected', 2, TRUE );
- Class smtp {
- Var $ connection;
- 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;
- /***************************************
- ** Constructor function. Arguments:
- ** $ Params-An assoc array of parameters:
- **
- ** Host-The hostname of the smtp server Default: localhost
- ** Port-The port the smtp server runs on Default: 25
- ** Helo-What to send as the HELO command Default: localhost
- ** (Typically the hostname of
- ** Machine this script runs on)
- ** Auth-Whether to use basic authentication Default: FALSE
- ** User-Username for authentication Default:
- ** Pass-Password for authentication Default:
- ** Timeout-The timeout in seconds for the call Default: 5
- ** To fsockopen ()
- ***************************************/
- Function smtp ($ params = array ()){
- If (! Defined ('crlf '))
- Define ('crlf ', "\ r \ n", TRUE );
- $ This-> timeout = 5;
- $ This-> status = SMTP_STATUS_NOT_CONNECTED;
- $ This-> host = 'localhost ';
- $ This-> port = 25;
- $ This-> helo = 'localhost ';
- $ This-> auth = FALSE;
- $ This-> user = '';
- $ This-> pass = '';
- $ This-> errors = array ();
- Foreach ($ params as $ key => $ value ){
- $ This-> $ key = $ value;
- }
- }
- /***************************************
- ** Connect function. This will, when called
- ** Statically, create a new smtp object,
- ** Call the connect function (ie this function)
- ** And return it. When not called statically,
- ** It will connect to the server and send
- ** The HELO command.
- ***************************************/
- Function connect ($ params = array ()){
- If (! Isset ($ this-> status )){
- $ Obj = new smtp ($ params );
- If ($ obj-> connect ()){
- $ Obj-> status = SMTP_STATUS_CONNECTED;
- }
- Return $ obj;
- } Else {
- $ This-> connection = fsockopen ($ this-> host, $ this-> port, $ errno, $ errstr, $ this-> timeout );
- Socket_set_timeout ($ this-> Connections, 0, 250000 );
- $ Greeting = $ this-> get_data ();
- If (is_resource ($ this-> connection )){
- Return $ this-> auth? $ This-> ehlo (): $ this-> helo ();
- } Else {
- $ This-> errors [] = 'failed' to connect to server: '. $ errstr;
- Return FALSE;
- }
- }
- }
- /***************************************
- ** Function which handles sending the mail.
- ** Arguments:
- ** $ Params-Optional assoc array of parameters.
- ** Can contain:
- ** Recipients-Indexed array of recipients
- ** From-The from address. (used in mail from,
- ** This will be the return path
- ** Headers-Indexed array of headers, one header per array entry
- ** Body-The body of the email
- ** It can also contain any of the parameters from the connect ()
- ** Function
- ***************************************/
- Function send ($ params = array ()){
- Foreach ($ params as $ key => $ value ){
- $ This-> set ($ key, $ value );
- }
- If ($ this-> is_connected ()){
- // Do we auth or not? Note the distinction between the auth variable and auth () function
- 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-> recipients );
- If (! $ This-> data ())
- Return FALSE;
- // Transparency
- $ 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) === '20140901 ');
- } Else {
- $ This-> errors [] = 'not ccted! ';
- Return FALSE;
- }
- }
- /***************************************
- ** Function to implement HELO cmd
- ***************************************/
- Function helo (){
- If (is_resource ($ this-> connection)
- AND $ this-> send_data ('helo'. $ this-> HELO)
- AND substr (trim ($ error = $ this-> get_data (), 0, 3) = '20140901 '){
- Return TRUE;
- } Else {
- $ This-> errors [] = 'Helo command failed, output: '. trim (substr (trim ($ error), 3 ));
- Return FALSE;
- }
- }
- /***************************************
- ** Function to implement EHLO cmd
- ***************************************/
- Function ehlo (){
- If (is_resource ($ this-> connection)
- AND $ this-> send_data ('ehlo'. $ this-> helo)
- AND substr (trim ($ error = $ this-> get_data (), 0, 3) = '20140901 '){
- Return TRUE;
- } Else {
- $ This-> errors [] = 'ehlo command failed, output: '. trim (substr (trim ($ error), 3 ));
- Return FALSE;
- }
- }
- /***************************************
- ** Function to implement AUTH cmd
- ***************************************/
- Function auth (){
- If (is_resource ($ this-> connection)
- AND $ this-> send_data ('auth login ')
- AND substr (trim ($ error = $ this-> get_data (), 0, 3) = '20140901'
- AND $ this-> send_data (base64_encode ($ this-> user) // Send username
- AND substr (trim ($ error = $ this-> get_data (), 334) = '20140901'
- AND $ this-> send_data (base64_encode ($ this-> pass) // Send password
- AND substr (trim ($ error = $ this-> get_data (), 235) = '20140901 '){
- Return TRUE;
- } Else {
- $ This-> errors [] = 'auth command failed: '. trim (substr (trim ($ error), 3 ));
- Return FALSE;
- }
- }
- /***************************************
- ** Function that handles the mail from: cmd
- ***************************************/
- Function mail ($ from ){
- If ($ this-> is_connected ()
- AND $ this-> send_data ('mail FROM: <'. $ from.'> ')
- AND substr (trim ($ this-> get_data (), 0, 2) === '20140901 '){
- Return TRUE;
- } Else
- Return FALSE;
- }
- /***************************************
- ** Function that handles the rcpt to: cmd
- ***************************************/
- Function rcpt ($ ){
- If ($ this-> is_connected ()
- AND $ this-> send_data ('rcpt TO: <'. $ to.'> ')
- AND substr (trim ($ error = $ this-> get_data (), 0, 2) = '25 '){
- Return TRUE;
- } Else {
- $ This-> errors [] = trim (substr (trim ($ error), 3 ));
- Return FALSE;
- }
- }
- /***************************************
- ** Function that sends the DATA cmd
- ***************************************/
- Function data (){
- If ($ this-> is_connected ()
- AND $ this-> send_data ('data ')
- AND substr (trim ($ error = $ this-> get_data (), 0, 3) = '20140901 '){
- Return TRUE;
- } Else {
- $ This-> errors [] = trim (substr (trim ($ error), 3 ));
- Return FALSE;
- }
- }
- /***************************************
- ** Function to determine if this object
- ** Is connected to the server or not.
- ***************************************/
- Function is_connected (){
- Return (is_resource ($ this-> connection) AND ($ this-> status === SMTP_STATUS_CONNECTED ));
- }
- /***************************************
- ** Function to send a bit of data
- ***************************************/
- Function send_data ($ data ){
- If (is_resource ($ this-> connection )){
- Return fwrite ($ this-> connection, $ data. CRLF, strlen ($ data) + 2 );
- } Else
- Return FALSE;
- }
- /***************************************
- ** Function to get data.
- ***************************************/
- Function & get_data (){
- $ Return = '';
- $ Line = '';
- If (is_resource ($ this-> connection )){
- While (strpos ($ return, CRLF) === false or substr ($ line, 3,1 )! = ''){
- $ Line = fgets ($ this-> connection, 512 );
- $ Return. = $ line;
- }
- Return $ return;
- } Else
- Return FALSE;
- }
- /***************************************
- ** Sets a variable
- ***************************************/
- Function set ($ var, $ value ){
- $ This-> $ var = $ value;
- Return TRUE;
- }
- } // End of class
- ?>
|