Home >Backend Development >PHP Tutorial >Random fixed-length integers and various server request methods are listed

Random fixed-length integers and various server request methods are listed

WBOY
WBOYOriginal
2016-07-25 09:06:45691browse

Random fixed-length integers and various server request methods are listed

  1. 1. Randomly generate integer function (number of generated digits: $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. Request a list of various methods
  12. "Method 1."
  13. $url="http://www.test.com/ssl/...";
  14. $opts = array(
  15. 'http'=>array (
  16. 'timeout' => 25,
  17. 'method' => "GET",
  18. 'header' => "Accept-language: enrn" .
  19. "Cookie: foo=barrn",
  20. )
  21. );
  22. $context = stream_context_create($opts);
  23. $xmlstr = file_get_contents($url,false,$context);
  24. $xmlstr = trim($xmlstr);
  25. 《Method 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. 《Method 3.》
  37. $url="http://www.test.com/ssl/...";
  38. echo "";
Copy code


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