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
- Error handling in PHP
- How to Fix a 401 Unauthorized Error?
- Error Handling in Express
- jQuery | error() Method
- Error Handling in Perl
- HTML | DOM console.error() Method
- Node.js | console.error() Function
- Why error "$ is not defined" occurred in jQuery ?
- HTML | DOM Audio error Property
- HTML | DOM Video error Property
- Python | 404 Error handling in Flask
- How to avoid undefined offset error in PHP ?
- How to avoid Compile Error while defining Variables
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.