搜索
首页后端开发php教程取得随机字符串

取得随机字符串
  1. /*
  2. 作用:取得随机字符串
  3. 参数:
  4. 1、(int)$length = 32 #随机字符长度,默认为32
  5. 2、(int)$mode = 0 #随机字符类型,0为大小写英文和数字,1为数字,2为小写子木,3为大写字母,4为大小写字母,5为大写字母和数字,6为小写字母和数字
  6. 返回:取得的字符串
  7. 使用:
  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 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
  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. 取得客户端信息
  47. /*
  48. 作用:取得客户端信息
  49. 参数:
  50. 返回:指定的资料
  51. 使用:
  52. $code = new clientGetObj;
  53. 1、浏览器:$str = $code->getBrowse();
  54. 2、IP地址:$str = $code->getIP();
  55. 4、操作系统:$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 substrGB ($str = '', $start = '', $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. //下载自某e文网站
  240. /***************************************
  241. ** Filename.......: class.smtp.inc
  242. ** Project........: SMTP Class
  243. ** Version........: 1.00b
  244. ** Last Modified..: 30 September 2001
  245. ***************************************/
  246. define('SMTP_STATUS_NOT_CONNECTED', 1, TRUE);
  247. define('SMTP_STATUS_CONNECTED', 2, TRUE);
  248. class smtp{
  249. var $connection;
  250. var $recipients;
  251. var $headers;
  252. var $timeout;
  253. var $errors;
  254. var $status;
  255. var $body;
  256. var $from;
  257. var $host;
  258. var $port;
  259. var $helo;
  260. var $auth;
  261. var $user;
  262. var $pass;
  263. /***************************************
  264. ** Constructor function. Arguments:
  265. ** $params - An assoc array of parameters:
  266. **
  267. ** host - The hostname of the smtp server Default: localhost
  268. ** port - The port the smtp server runs on Default: 25
  269. ** helo - What to send as the HELO command Default: localhost
  270. ** (typically the hostname of the
  271. ** machine this script runs on)
  272. ** auth - Whether to use basic authentication Default: FALSE
  273. ** user - Username for authentication Default:
  274. ** pass - Password for authentication Default:
  275. ** timeout - The timeout in seconds for the call Default: 5
  276. ** to fsockopen()
  277. ***************************************/
  278. function smtp($params = array()){
  279. if(!defined('CRLF'))
  280. define('CRLF', "\r\n", TRUE);
  281. $this->timeout = 5;
  282. $this->status = SMTP_STATUS_NOT_CONNECTED;
  283. $this->host = 'localhost';
  284. $this->port = 25;
  285. $this->helo = 'localhost';
  286. $this->auth = FALSE;
  287. $this->user = '';
  288. $this->pass = '';
  289. $this->errors = array();
  290. foreach($params as $key => $value){
  291. $this->$key = $value;
  292. }
  293. }
  294. /***************************************
  295. ** Connect function. This will, when called
  296. ** statically, create a new smtp object,
  297. ** call the connect function (ie this function)
  298. ** and return it. When not called statically,
  299. ** it will connect to the server and send
  300. ** the HELO command.
  301. ***************************************/
  302. function connect($params = array()){
  303. if(!isset($this->status)){
  304. $obj = new smtp($params);
  305. if($obj->connect()){
  306. $obj->status = SMTP_STATUS_CONNECTED;
  307. }
  308. return $obj;
  309. }else{
  310. $this->connection = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
  311. socket_set_timeout($this->connection, 0, 250000);
  312. $greeting = $this->get_data();
  313. if(is_resource($this->connection)){
  314. return $this->auth ? $this->ehlo() : $this->helo();
  315. }else{
  316. $this->errors[] = 'Failed to connect to server: '.$errstr;
  317. return FALSE;
  318. }
  319. }
  320. }
  321. /***************************************
  322. ** Function which handles sending the mail.
  323. ** Arguments:
  324. ** $params - Optional assoc array of parameters.
  325. ** Can contain:
  326. ** recipients - Indexed array of recipients
  327. ** from - The from address. (used in MAIL FROM,
  328. ** this will be the return path
  329. ** headers - Indexed array of headers, one header per array entry
  330. ** body - The body of the email
  331. ** It can also contain any of the parameters from the connect()
  332. ** function
  333. ***************************************/
  334. function send($params = array()){
  335. foreach($params as $key => $value){
  336. $this->set($key, $value);
  337. }
  338. if($this->is_connected()){
  339. // Do we auth or not? Note the distinction between the auth variable and auth() function
  340. if($this->auth){
  341. if(!$this->auth())
  342. return FALSE;
  343. }
  344. $this->mail($this->from);
  345. if(is_array($this->recipients))
  346. foreach($this->recipients as $value)
  347. $this->rcpt($value);
  348. else
  349. $this->rcpt($this->recipients);
  350. if(!$this->data())
  351. return FALSE;
  352. // Transparency
  353. $headers = str_replace(CRLF.'.', CRLF.'..', trim(implode(CRLF, $this->headers)));
  354. $body = str_replace(CRLF.'.', CRLF.'..', $this->body);
  355. $body = $body[0] == '.' ? '.'.$body : $body;
  356. $this->send_data($headers);
  357. $this->send_data('');
  358. $this->send_data($body);
  359. $this->send_data('.');
  360. return (substr(trim($this->get_data()), 0, 3) === '250');
  361. }else{
  362. $this->errors[] = 'Not connected!';
  363. return FALSE;
  364. }
  365. }
  366. /***************************************
  367. ** Function to implement HELO cmd
  368. ***************************************/
  369. function helo(){
  370. if(is_resource($this->connection)
  371. AND $this->send_data('HELO '.$this->helo)
  372. AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){
  373. return TRUE;
  374. }else{
  375. $this->errors[] = 'HELO command failed, output: ' . trim(substr(trim($error),3));
  376. return FALSE;
  377. }
  378. }
  379. /***************************************
  380. ** Function to implement EHLO cmd
  381. ***************************************/
  382. function ehlo(){
  383. if(is_resource($this->connection)
  384. AND $this->send_data('EHLO '.$this->helo)
  385. AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){
  386. return TRUE;
  387. }else{
  388. $this->errors[] = 'EHLO command failed, output: ' . trim(substr(trim($error),3));
  389. return FALSE;
  390. }
  391. }
  392. /***************************************
  393. ** Function to implement AUTH cmd
  394. ***************************************/
  395. function auth(){
  396. if(is_resource($this->connection)
  397. AND $this->send_data('AUTH LOGIN')
  398. AND substr(trim($error = $this->get_data()), 0, 3) === '334'
  399. AND $this->send_data(base64_encode($this->user)) // Send username
  400. AND substr(trim($error = $this->get_data()),0,3) === '334'
  401. AND $this->send_data(base64_encode($this->pass)) // Send password
  402. AND substr(trim($error = $this->get_data()),0,3) === '235' ){
  403. return TRUE;
  404. }else{
  405. $this->errors[] = 'AUTH command failed: ' . trim(substr(trim($error),3));
  406. return FALSE;
  407. }
  408. }
  409. /***************************************
  410. ** Function that handles the MAIL FROM: cmd
  411. ***************************************/
  412. function mail($from){
  413. if($this->is_connected()
  414. AND $this->send_data('MAIL FROM:')
  415. AND substr(trim($this->get_data()), 0, 2) === '250' ){
  416. return TRUE;
  417. }else
  418. return FALSE;
  419. }
  420. /***************************************
  421. ** Function that handles the RCPT TO: cmd
  422. ***************************************/
  423. function rcpt($to){
  424. if($this->is_connected()
  425. AND $this->send_data('RCPT TO:')
  426. AND substr(trim($error = $this->get_data()), 0, 2) === '25' ){
  427. return TRUE;
  428. }else{
  429. $this->errors[] = trim(substr(trim($error), 3));
  430. return FALSE;
  431. }
  432. }
  433. /***************************************
  434. ** Function that sends the DATA cmd
  435. ***************************************/
  436. function data(){
  437. if($this->is_connected()
  438. AND $this->send_data('DATA')
  439. AND substr(trim($error = $this->get_data()), 0, 3) === '354' ){
  440. return TRUE;
  441. }else{
  442. $this->errors[] = trim(substr(trim($error), 3));
  443. return FALSE;
  444. }
  445. }
  446. /***************************************
  447. ** Function to determine if this object
  448. ** is connected to the server or not.
  449. ***************************************/
  450. function is_connected(){
  451. return (is_resource($this->connection) AND ($this->status === SMTP_STATUS_CONNECTED));
  452. }
  453. /***************************************
  454. ** Function to send a bit of data
  455. ***************************************/
  456. function send_data($data){
  457. if(is_resource($this->connection)){
  458. return fwrite($this->connection, $data.CRLF, strlen($data)+2);
  459. }else
  460. return FALSE;
  461. }
  462. /***************************************
  463. ** Function to get data.
  464. ***************************************/
  465. function &get_data(){
  466. $return = '';
  467. $line = '';
  468. if(is_resource($this->connection)){
  469. while(strpos($return, CRLF) === FALSE OR substr($line,3,1) !== ' '){
  470. $line = fgets($this->connection, 512);
  471. $return .= $line;
  472. }
  473. return $return;
  474. }else
  475. return FALSE;
  476. }
  477. /***************************************
  478. ** Sets a variable
  479. ***************************************/
  480. function set($var, $value){
  481. $this->$var = $value;
  482. return TRUE;
  483. }
  484. } // End of class
  485. ?>
复制代码


声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
11个最佳PHP URL缩短脚本(免费和高级)11个最佳PHP URL缩短脚本(免费和高级)Mar 03, 2025 am 10:49 AM

长URL(通常用关键字和跟踪参数都混乱)可以阻止访问者。 URL缩短脚本提供了解决方案,创建了简洁的链接,非常适合社交媒体和其他平台。 这些脚本对于单个网站很有价值

在Laravel中使用Flash会话数据在Laravel中使用Flash会话数据Mar 12, 2025 pm 05:08 PM

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

构建具有Laravel后端的React应用程序:第2部分,React构建具有Laravel后端的React应用程序:第2部分,ReactMar 04, 2025 am 09:33 AM

这是有关用Laravel后端构建React应用程序的系列的第二个也是最后一部分。在该系列的第一部分中,我们使用Laravel为基本的产品上市应用程序创建了一个RESTFUL API。在本教程中,我们将成为开发人员

简化的HTTP响应在Laravel测试中模拟了简化的HTTP响应在Laravel测试中模拟了Mar 12, 2025 pm 05:09 PM

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

php中的卷曲:如何在REST API中使用PHP卷曲扩展php中的卷曲:如何在REST API中使用PHP卷曲扩展Mar 14, 2025 am 11:42 AM

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

在Codecanyon上的12个最佳PHP聊天脚本在Codecanyon上的12个最佳PHP聊天脚本Mar 13, 2025 pm 12:08 PM

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

宣布 2025 年 PHP 形势调查宣布 2025 年 PHP 形势调查Mar 03, 2025 pm 04:20 PM

2025年的PHP景观调查调查了当前的PHP发展趋势。 它探讨了框架用法,部署方法和挑战,旨在为开发人员和企业提供见解。 该调查预计现代PHP Versio的增长

Laravel中的通知Laravel中的通知Mar 04, 2025 am 09:22 AM

在本文中,我们将在Laravel Web框架中探索通知系统。 Laravel中的通知系统使您可以通过不同渠道向用户发送通知。今天,我们将讨论您如何发送通知OV

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
1 个月前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)