Check whether a php code exists in the remote file

Source: Internet
Author: User
Check whether a php code exists in the remote file

  1. /**

  2. Php checks whether remote files exist
  3. By http://bbs.it-home.org
  4. */
  5. Function get_http_response_code ($ theURL ){
  6. $ Headers = get_headers ($ theURL );
  7. Return substr ($ headers [0], 9, 3 );
  8. }

  9. /**

  10. * Fetches all the real headers sent by the server in response to a HTTP request without redirects
  11. * Obtain a header that does not contain redirection.
  12. */
  13. Function get_real_headers ($ url, $ format = 0, $ follow_redirect = 0 ){
  14. If (! $ Follow_redirect ){
  15. // Set new default options
  16. $ Opts = array ('http' =>
  17. Array ('max _ redirects' => 1, 'Ignore _ errors '=> 1)
  18. );
  19. Stream_context_get_default ($ opts );
  20. }
  21. // Get headers
  22. $ Headers = get_headers ($ url, $ format );
  23. // Restore default options
  24. If (isset ($ opts )){
  25. $ Opts = array ('http' =>
  26. Array ('max _ redirects' => 20, 'Ignore _ errors '=> 0)
  27. );
  28. Stream_context_get_default ($ opts );
  29. }
  30. // Return
  31. Return $ headers;
  32. }
  33. ?>

For how to determine the curl method, refer to: php code that uses curl to determine whether a remote file exists.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.