Check if links are broken in php

前端 未结 4 1687
盖世英雄少女心
盖世英雄少女心 2020-12-05 01:00

I wonder if there is any good PHP script (libraries) to check if link are broken? I have links to documents in a mysql table and could possibly just check if the link leads

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 01:38

    As quick workaround check, you can use the global variable $http_response_header with file_get_contents() function.

    For example (extracted from PHP documentation):

    Then check the status code in first line for a "HTTP/1.1 200 OK" or other HTTP status codes.

提交回复
热议问题