What is the fastest way to determine if a URL exists in PHP?

前端 未结 3 1596
借酒劲吻你
借酒劲吻你 2021-01-06 04:57

I need to create a function that returns if a URL is reachable or valid.

I am currently using something like the following to determine a valid url:

         


        
3条回答
  •  被撕碎了的回忆
    2021-01-06 05:47

    You could check http status code.

    Here is a code you could use to check that an url returns 2xx or 3xx http code to ensure the url works.

    
    

    Hope this helps!

提交回复
热议问题