Get random string
- /*
- Function: Get random string
- Parameters:
- 1, (int) $length = #随机字符长度, default is 32
- 2, (int) $mode = 0 #随机字符类型, 0 for the case of English and numerals, 1 for numbers, 2 for lowercase, 3 for uppercase, 4 for uppercase and lowercase, 5 for lowercase letters and numbers, 6 for small letters and numbers
- Return: The obtained string
- Use:
- $code = new Activecodeobj;
- $str = $code->getcode ($length, $mode);
- */
- Class Activecodeobj
- {
- function GetCode ($length = +, $mode = 0)
- {
- Switch ($mode) {
- Case ' 1 ':
- $str = ' 1234567890 ';
- Break
- Case ' 2 ':
- $str = ' abcdefghijklmnopqrstuvwxyz ';
- Break
- Case ' 3 ':
- $str = ' abcdefghijklmnopqrstuvwxyz ';
- Break
- Case ' 4 ':
- $str = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ';
- 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;
- }
- }
- Get client Information
- /*
- Role: Obtain client information
- Parameters:
- Returns: the specified data
- Use:
- $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 (' + ', $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 (' Offline ', $agent)) {
- $os = ' offline ';
- }
- else {
- $os = ' Unknown ';
- }
- return $os;
- }
- }
- Modified 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));
- $tmpstr 2 = Ord (substr ($str, $i +1, 1));
- if (($tmpstr <= 161 | | $tmpstr >= 247) && ($tmpstr 2 <= 161 | | $tmpstr 2 >= 247)) {
- $legalflag = false;
- } else {
- $legalflag = true;
- }
- }
- return $legalflag;
- }
- }
- Download from an e-text website
- /***************************************
- * * Filename ...: class.smtp.inc
- * * Project ...: SMTP Class
- * * Version ...: 1.00b
- * * Last Modified: 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 the
- * * 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 would, when called
- * * Statically, create a new SMTP object,
- * * Call the Connect function (ie this function)
- * * and return it. When not called statically,
- * * It would 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->connection, 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'll 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) = = = ' 250 ');
- }else{
- $this->errors[] = ' not connected! ';
- 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) = = = ' 250 ') {
- 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) = = = ' 250 ') {
- 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) = = = ' 334 '
- and $this->send_data (Base64_encode ($this->user))//Send username
- and substr (Trim ($error = $this->get_data ()), 0, 3) = = = ' 334 '
- and $this->send_data (Base64_encode ($this->pass))//Send password
- and substr (Trim ($error = $this->get_data ()), 0, 3) = = = ' 235 ') {
- 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) = = = ' 250 ') {
- return TRUE;
- }else
- return FALSE;
- }
- /***************************************
- * * Function that handles the RCPT To:cmd
- ***************************************/
- Function Rcpt ($to) {
- 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) = = = ' 354 ') {
- return TRUE;
- }else{
- $this->errors[] = Trim (substr (Trim ($error), 3));
- return FALSE;
- }
- }
- /***************************************
- * * Function to determine if the 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
- ?>
Copy Code |