随机固定长度整数以及 各种服务器请求方法罗列

  1. 1。随机生成整数函数(生成位数:$pw_length)
  2. public function randk($pw_length)
  3. {
  4. $randpwd = '';
  5. for ($i=0;$i<$pw_length;$i++)
  6. {
  7. $randpwd .= chr(mt_rand(48,57));
  8. }
  9. return $randpwd;
  10. }
  11. 2。请求罗列各种方法
  12. 《方法1.》
  13. $url="http://www.test.com/ssl/...";
  14. $opts = array(
  15. 'http'=>array(
  16. 'timeout' => 25,
  17. 'method' => "GET",
  18. 'header' => "Accept-language: en\r\n" .
  19. "Cookie: foo=bar\r\n",
  20. )
  21. );
  22. $context = stream_context_create($opts);
  23. $xmlstr = file_get_contents($url,false,$context);
  24. $xmlstr = trim($xmlstr);
  25. 《方法2.》
  26. function cuel_get_contents($url,$timeout=1) {
  27. $curlHandle = curl_init();
  28. curl_setopt( $curlHandle , CURLOPT_URL, $url );
  29. curl_setopt( $curlHandle , CURLOPT_RETURNTRANSFER, 1 );
  30. curl_setopt( $curlHandle , CURLOPT_TIMEOUT, $timeout );
  31. $result = curl_exec( $curlHandle );
  32. curl_close( $curlHandle );
  33. return $result;
  34. }
  35. $hx =cuel_get_contents('http://www.test.com');
  36. 《方法3.》
  37. $url="http://www.test.com/ssl/...";
  38. echo "";
复制代码


09-07 21:53