Existence of an URL can be checked by checking the status code in the response header. The status code 200 is Standard response for successful HTTP requests and status code 404 means URL doesn’t exist.
- get_headers() Function: It fetches all the headers sent by the server in response to the HTTP request.
- strpos() Function: This function is used to find the first occurrence of a string into another string.
Example 1: This example checks for the status code 200 in response header. If the status code is 200, it indicates URL exist otherwise not.
Example 2: This example checks for the status code 404 in response header. If the status code is 404, it indicates URL doesn’t exist otherwise URL exist.
URL Doesn't Exist
Example 3: This example uses curl_init() method to check the existence of an URL.
URL Doesn't Exist
- PHP | check if a number is Even or Odd
- How to check if URL contain certain string using PHP?
- PHP | Palindrome Check
- How to check if a scrollbar is visible?
- PHP program to check for Anagram
- How to check whether an object is a date?
- How to check an array is multidimensional or not in PHP ?
- PHP to check substring in a string
- PHP | Check if a number is prime
- How to check whether an array is empty using PHP?
- HTML | Spell Check
- Check if a jquery has been loaded or not
- How to check if an element is visible in DOM ?
- PHP | ctype_alnum() (Check for Alphanumeric)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.