Checking if a Webpage URL exists or not is relatively easy in PHP. If the required URL does not exist, then it will return 404 error. The checking can be done with and without using cURL library.
cURL: The cURL stands for ‘Client for URLs’, originally with URL spelled in uppercase to make it obvious that it deals with URLs. It is pronounced as ‘see URL’. The cURL project has two products libcurl and curl.
- libcurl: A free and easy-to-use client-side URL transfer library, supporting FTP, TPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE, and LDAP. libcurl supports TTPS certificates, HTTP POST, HTTP PUT, FTP uploading, kerberos, HTTP based upload, proxies, cookies, user & password authentication, file transfer resume, HTTP proxy tunneling and many more. libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported and fast.
- curl: A command line tool for getting or sending files using URL syntax. Since curl uses libcurl, it supports a range of common internal protocols, currently including HTTP, HTTPS, FTP, FTPS, GOPHER, TELNET, DICT, and FILE.
Example 1: This example test a URL for 404 error without using cURL approach.
Specified URL exists
Example 2: This example test a URL for 404 error using cURL approach.
Specified URL exists
- Handling 404 Error in Flask
- Error handling in PHP
- Where does PHP store the error log? (php5, apache, fastcgi, cpanel)
- How to avoid undefined offset error in PHP ?
- PHP | fopen( ) (Function open file or URL)
- Get the full URL in PHP
- How to check if URL contain certain string using PHP?
- Program to get the subdomain of a URL using PHP
- Saving an Image from URL in PHP
- How to add http:// if it doesn't exists in the URL in PHP?
- Download file from URL using PHP
- How to get parameters from a URL string in PHP?
- How to check the existence of URL in PHP?
- How to download a CSV file in PHP that is triggered through a URL ?
- How to remove error Call to undefined function curl_init()?
- HTML | DOM console.error() Method
- jQuery | error() Method
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.