search

Get random string
  1. /*
  2. Function: Get a random string
  3. Parameters:
  4. 1, (int)$length = 32 #Random character length, the default is 32
  5. 2, (int)$mode = 0 # Random character type, 0 is uppercase and lowercase letters and numbers, 1 is numbers, 2 is lowercase letters, 3 is uppercase letters, 4 is uppercase and lowercase letters, 5 is uppercase letters and numbers, 6 is lowercase letters and numbers
  6. Return: Get String
  7. Use:
  8. $code = new activeCodeObj;
  9. $str = $code->getCode($length, $mode);
  10. */
  11. class activeCodeObj
  12. {
  13. function getCode ($length = 32, $mode) = 0)
  14. {
  15. switch ($mode) {
  16. case '1':
  17. $str = '1234567890';
  18. break;
  19. case '2':
  20. $str = 'abcdefghijklmnopqrstuvwxyz';
  21. break;
  22. case '3 ':
  23. $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  24. break;
  25. case '4':
  26. $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  27. break;
  28. case '5':
  29. $str = 'ABCDEFGHIJKLMNOPQRSTUVWX YZ1234567890';
  30. break;
  31. case ' 6':
  32. $str = 'abcdefghijklmnopqrstuvwxyz1234567890';
  33. break;
  34. default:
  35. $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
  36. break;
  37. }
  38. $result = '';
  39. $l = strlen($str);
  40. for($i = 0;$i $num = rand(0, $l);
  41. $result .= $str[$num];
  42. }
  43. return $result ;
  44. }
  45. }
  46. Get client information
  47. /*
  48. Function: Get client information
  49. Parameters:
  50. Return: Specified information
  51. Usage:
  52. $code = new clientGetObj;
  53. 1. Browser: $str = $ code->getBrowse();
  54. 2. IP address: $str = $code->getIP();
  55. 4. Operating system: $str = $code->getOS();
  56. */
  57. class clientGetObj
  58. {
  59. function getBrowse()
  60. {
  61. global $_SERVER;
  62. $Agent = $_SERVER['HTTP_USER_AGENT'];
  63. $browser = '';
  64. $browserver = '';
  65. $Browser = array('Lynx' , 'MOSAIC', 'AOL', 'Opera', 'JAVA', 'MacWeb', 'WebExplorer', 'OmniWeb');
  66. for($i = 0; $i if(strpos($Agent, $Browsers[$i])){
  67. $browser = $Browsers[$i];
  68. $browserver = '';
  69. }
  70. }
  71. if(ereg('Mozilla', $ Agent) && !ereg('MSIE', $Agent)){
  72. $temp = explode('(', $Agent);
  73. $Part = $temp[0];
  74. $temp = explode('/', $ Part);
  75. $browserver = $temp[1];
  76. $temp = explode(' ', $browserver);
  77. $browserver = $temp[0];
  78. $browserver = preg_replace('/([d.]+ )/', '1', $browserver);
  79. $browserver = $browserver;
  80. $browser = 'Netscape Navigator';
  81. }
  82. if(ereg('Mozilla', $Agent) && ereg('Opera', $ Agent)) {
  83. $temp = explode('(', $Agent);
  84. $Part = $temp[1];
  85. $temp = explode(')', $Part);
  86. $browserver = $temp[1 ];
  87. $temp = explode(' ', $browserver);
  88. $browserver = $temp[2];
  89. $browserver = preg_replace('/([d.]+)/', '1', $browserver) ;
  90. $browserver = $browserver;
  91. $browser = 'Opera';
  92. }
  93. if(ereg('Mozilla', $Agent) && ereg('MSIE', $Agent)){
  94. $temp = explode('( ', $Agent);
  95. $Part = $temp[1];
  96. $temp = explode(';', $Part);
  97. $Part = $temp[1];
  98. $temp = explode(' ', $ Part);
  99. $browserver = $temp[2];
  100. $browserver = preg_replace('/([d.]+)/','1',$browserver);
  101. $browserver = $browserver;
  102. $browser = 'Internet Explorer';
  103. }
  104. if($browser != ''){
  105. $browseinfo = $browser.' '.$browserver;
  106. } else {
  107. $browseinfo = false;
  108. }
  109. return $browseinfo;
  110. }
  111. function getIP ()
  112. {
  113. global $_SERVER;
  114. if (getenv('HTTP_CLIENT_IP')) {
  115. $ip = getenv('HTTP_CLIENT_IP');
  116. } else if (getenv('HTTP_X_FORWARDED_FOR')) {
  117. $ ip = getenv('HTTP_X_FORWARDED_FOR');
  118. } else if (getenv('REMOTE_ADDR')) {
  119. $ip = getenv('REMOTE_ADDR');
  120. } else {
  121. $ip = $_SERVER['REMOTE_ADDR'];
  122. }
  123. return $ip;
  124. }
  125. function getOS ()
  126. {
  127. global $_SERVER;
  128. $agent = $_SERVER['HTTP_USER_AGENT'];
  129. $os = false;
  130. if (eregi('win', $agent ) && strpos($agent, '95')){
  131. $os = 'Windows 95';
  132. }
  133. else if (eregi('win 9x', $agent) && strpos($agent, '4.90')){
  134. $os = 'Windows ME';
  135. }
  136. else if (eregi('win', $agent) && ereg('98', $agent)){
  137. $os = 'Windows 98';
  138. }
  139. else if (eregi('win', $agent) && eregi('nt 5.1', ​​$agent)){
  140. $os = 'Windows XP';
  141. }
  142. else if (eregi('win', $agent) && eregi( 'nt 5', $agent)){
  143. $os = 'Windows 2000';
  144. }
  145. else if (eregi('win', $agent) && eregi('nt', $agent)){
  146. $os = 'Windows NT';
  147. }
  148. else if (eregi('win', $agent) && ereg('32', $agent)){
  149. $os = 'Windows 32';
  150. }
  151. else if (eregi(' linux', $agent)){
  152. $os = 'Linux';
  153. }
  154. else if (eregi('unix', $agent)){
  155. $os = 'Unix';
  156. }
  157. else if (eregi(' sun', $agent) && eregi('os', $agent)){
  158. $os = 'SunOS';
  159. }
  160. else if (eregi('ibm', $agent) && eregi('os', $agent )){
  161. $os = 'IBM OS/2';
  162. }
  163. else if (eregi('Mac', $agent) && eregi('PC', $agent)){
  164. $os = 'Macintosh';
  165. }
  166. else if (eregi('PowerPC', $agent)){
  167. $os = 'PowerPC';
  168. }
  169. else if (eregi('AIX', $agent)){
  170. $os = 'AIX';
  171. }
  172. else if (eregi('HPUX', $agent)){
  173. $os = 'HPUX';
  174. }
  175. else if (eregi('NetBSD', $agent)){
  176. $os = 'NetBSD';
  177. }
  178. else if (eregi('BSD', $agent)){
  179. $os = 'BSD';
  180. }
  181. else if (ereg('OSF1', $agent)){
  182. $os = 'OSF1';
  183. }
  184. else if (ereg('IRIX', $agent)){
  185. $os = 'IRIX';
  186. }
  187. else if (eregi('FreeBSD', $agent)){
  188. $os = 'FreeBSD';
  189. }
  190. else if (eregi('teleport', $agent)){
  191. $os = 'teleport';
  192. }
  193. else if (eregi('flashget', $agent)){
  194. $os = 'flashget';
  195. }
  196. else if (eregi('webzip', $agent)){
  197. $os = 'webzip';
  198. }
  199. else if (eregi('offline', $agent)){
  200. $os = 'offline';
  201. }
  202. else {
  203. $os = 'Unknown';
  204. }
  205. return $os;
  206. }
  207. }
  208. //修改自q3boy
  209. class cnStrObj
  210. {
  211. ''$function = $tstr = star , $len = ''){
  212. if($start == 0 || $start == ''){
  213. $start = 1;
  214. }
  215. if($str == '' || $len == ' '){
  216. return false;
  217. }
  218. for($i = 0; $i $tmpstr = (ord($str[$i]) >= 161 && ord($str[$i]) = 161 && ord($str[$i+1]) if ($i >= $start && $i {
  219. $tmp .=$tmpstr;
  220. }
  221. }
  222. return $tmp;
  223. }
  224. function isGB ($str)
  225. {
  226. $strLen = strlen($str);
  227. $length = 1;
  228. for($i = 0; $i $tmpstr = ord(substr($str, $i, 1));
  229. $tmpstr2 = ord( substr($str, $i+1, 1));
  230. if(($tmpstr = 247) && ($tmpstr2 = 247) ){
  231. $legalflag = false;
  232. } else {
  233. $legalflag = true;
  234. }
  235. }
  236. return $legalflag;
  237. }
  238. }
  239. //
  240. define('SMTP_STATUS_NOT_CONNECTED', 1, TRUE);
  241. define('SMTP_STATUS_CONNECTED', 2, TRUE);
  242. class smtp{
  243. var $connection;
  244. var $connection; var $timeout ;
  245. var $errors;
  246. var $status;
  247. var $body;
  248. var $from;
  249. var $host;
  250. var $port;
  251. var $helo;
  252. var $auth;
  253. var $user;
  254. var $pass ;
  255. /***************************************
  256. ** Filename.......: class.smtp.inc
  257. ** Project........: SMTP Class
  258. ** Version........: 1.00b
  259. ** Last Modified..: 30 September 2001
  260. ***************************************/
  261. function smtp($params = array()){
  262. if(!defined('CRLF'))
  263. define('CRLF', "rn", TRUE);
  264. $this->timeout = 5;
  265. $this->status = SMTP_STATUS_NOT_CONNECTED;
  266. $this->host = 'localhost';
  267. $this->port = 25;
  268. $this->thelo> = 'localhost';
  269. $this->auth = FALSE;
  270. $this->user = '';
  271. $this->pass = '';
  272. $this->errors = array();
  273. foreach($params as $key => $value){
  274. $this->$key = $value;
  275. }
  276. }
  277. /***************************************
  278. ** Constructor function. Arguments:
  279. ** $params - An assoc array of parameters:
  280. **
  281. ** host - The hostname of the smtp server Default: localhost
  282. ** port - The port the smtp server runs on Default: 25
  283. ** helo - What to send as the HELO command Default: localhost
  284. ** (typically the hostname of the
  285. ** machine this script runs on)
  286. ** auth - Whether to use basic authentication Default: FALSE
  287. ** user - Username for authentication Default:
  288. ** pass - Password for authentication Default:
  289. ** timeout - The timeout in seconds for the call Default: 5
  290. ** to fsockopen()
  291. ***************************************/
  292. function connect($params = array()){
  293. if(!isset( $this->status)){
  294. $obj = new smtp($params);
  295. if($obj->connect()){
  296. $obj->status = SMTP_STATUS_CONNECTED;
  297. }
  298. return $obj ;
  299. }else{
  300. $this->connection = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
  301. socket_set_timeout($this- >connection, 0, 250000);
  302. $greeting = $this->get_data();
  303. if(is_resource($this->connection)){
  304. return $this->auth ? $this->ehlo() : $this->helo();
  305. }else{
  306. $this->errors[] = 'Failed to connect to server: '.$errstr;
  307. return FALSE;
  308. }
  309. }
  310. }
  311. /***************************************
  312. ** Function which handles sending the mail.
  313. ** Arguments:
  314. ** $params - Optional assoc array of parameters.
  315. ** Can contain:
  316. ** recipients - Indexed array of recipients
  317. ** from - The from address. (used in MAIL FROM,
  318. ** this will be the return path
  319. ** headers - Indexed array of headers, one header per array entry
  320. ** body - The body of the email
  321. ** It can also contain any of the parameters from the connect()
  322. ** function
  323. ***************************************/
  324. function send($params = array()){
  325. foreach($params as $key => $value){
  326. $this->set($key, $value);
  327. }
  328. if($this->is_connected()){
  329. // Do we auth or not? Note the distinction between the auth variable and auth() function
  330. if($this->auth){
  331. if(!$this->auth())
  332. return FALSE;
  333. }
  334. $this->mail($this->from);
  335. if(is_array($this->recipients))
  336. foreach($this->recipients as $value)
  337. $this->rcpt($value);
  338. else
  339. $this->rcpt($this->recipients);
  340. if(!$this->data())
  341. return FALSE;
  342. // Transparency
  343. $headers = str_replace(CRLF.'.', CRLF.'..', trim(implode(CRLF, $this->headers)));
  344. $body = str_replace(CRLF.'.', CRLF.'..', $this->body);
  345. $body = $body[0] == '.' ? '.'.$body : $body;
  346. $this->send_data($headers);
  347. $this->send_data('');
  348. $this->send_data($body);
  349. $this->send_data('.');
  350. return (substr(trim($this->get_data()), 0, 3) === '250');
  351. }else{
  352. $this->errors[] = 'Not connected!';
  353. return FALSE;
  354. }
  355. }
  356. /***************************************
  357. ** Function to implement HELO cmd
  358. ***************************************/
  359. function helo(){
  360. if(is_resource($this->connection)
  361. AND $this->send_data('HELO '.$this->helo)
  362. AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){
  363. return TRUE;
  364. }else{
  365. $this->errors[] = 'HELO command failed, output: ' . trim(substr(trim($error),3));
  366. return FALSE;
  367. }
  368. }
  369. /***************************************
  370. ** Function to implement EHLO cmd
  371. ***************************************/
  372. function ehlo(){
  373. if(is_resource($this->connection)
  374. AND $this->send_data('EHLO '.$this->helo)
  375. AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){
  376. return TRUE;
  377. }else{
  378. $this->errors[] = 'EHLO command failed, output: ' . trim(substr(trim($error),3));
  379. return FALSE;
  380. }
  381. }
  382. /***************************************
  383. ** Function to implement AUTH cmd
  384. ***************************************/
  385. function auth(){
  386. if(is_resource($this->connection)
  387. AND $this->send_data('AUTH LOGIN')
  388. AND substr(trim($error = $this->get_data()), 0, 3) === '334'
  389. AND $this->send_data(base64_encode($this->user)) // Send username
  390. AND substr(trim($error = $this->get_data()),0,3) === '334'
  391. AND $this->send_data(base64_encode($this->pass)) // Send password
  392. AND substr(trim($error = $this->get_data()),0,3) === '235' ){
  393. return TRUE;
  394. }else{
  395. $this->errors[] = 'AUTH command failed: ' . trim(substr(trim($error),3));
  396. return FALSE;
  397. }
  398. }
  399. /***************************************
  400. ** Function that handles the MAIL FROM: cmd
  401. ***************************************/
  402. function mail($from){
  403. if($this->is_connected()
  404. AND $this->send_data('MAIL FROM:')
  405. AND substr(trim($this->get_data()), 0, 2) === '250' ){
  406. return TRUE;
  407. }else
  408. return FALSE;
  409. }
  410. /***************************************
  411. ** Function that handles the RCPT TO: cmd
  412. ***************************************/
  413. function rcpt($to){
  414. if($this->is_connected()
  415. AND $this->send_data('RCPT TO:')
  416. AND substr(trim($error = $this->get_data()), 0, 2) === '25' ){
  417. return TRUE;
  418. }else{
  419. $this->errors[] = trim(substr(trim($error), 3));
  420. return FALSE;
  421. }
  422. }
  423. /***************************************
  424. ** Function that sends the DATA cmd
  425. ***************************************/
  426. function data(){
  427. if($this->is_connected()
  428. AND $this->send_data('DATA')
  429. AND substr(trim($error = $this->get_data()), 0, 3) === '354' ){
  430. return TRUE;
  431. }else{
  432. $this->errors[] = trim(substr(trim($error), 3));
  433. return FALSE;
  434. }
  435. }
  436. /***************************************
  437. ** Function to determine if this object
  438. ** is connected to the server or not.
  439. ***************************************/
  440. function is_connected(){
  441. return (is_resource($this->connection) AND ($this->status === SMTP_STATUS_CONNECTED));
  442. }
  443. /***************************************
  444. ** Function to send a bit of data
  445. ***************************************/
  446. function send_data($data){
  447. if(is_resource($this->connection)){
  448. return fwrite($this->connection, $data.CRLF, strlen($data)+2);
  449. }else
  450. return FALSE;
  451. }
  452. /***************************************
  453. ** Function to get data.
  454. ***************************************/
  455. function &get_data(){
  456. $return = '';
  457. $line = '';
  458. if(is_resource($this->connection)){
  459. while(strpos($return, CRLF) === FALSE OR substr($line,3,1) !== ' '){
  460. $line = fgets($this->connection, 512);
  461. $return .= $line;
  462. }
  463. return $return;
  464. }else
  465. return FALSE;
  466. }
  467. /***************************************
  468. ** Sets a variable
  469. ***************************************/
  470. function set($var, $value){
  471. $this->$var = $value;
  472. return TRUE;
  473. }
  474. } // End of class
  475. ?>
复制代码


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.