PHP script for testing links on a web page
Link Checker scans all pages in your site and detects broken links and redirects.
The broken links tester is an indispensable tool for servicing the site, in relation to users and search engines. It is necessary to remove all broken links, as well as update redirects, whether external or internal to the site, for the correct image of the site and for better positioning.
This program is an alternative to the Xenu program, has the advantage of grouping results by tested pages, which makes editing easier, and it is portable.
Compared to the online validator, the W3C has the advantage of not being blocked on some pages.
In addition, this open source program is easy to edit using Script or PHP source code. It works with PHP 5 on almost all operating systems and computer models.
A Link Checker version with graphical UI is also available. It is more difficult to install, but easier to use .
Orders and Usage
The command line script can be executed by the Script PHP compiler:
solp linche [options] page
or directly by the PHP 5 interpreter:
php linche.php [options] page
The page is the full URL of the shape:
https://www.example.com/index.php
Parameters:
-r recursif, suivre les liens internes. Par défaut seule la page est testée.
-s liste courte (short) affiche seulement les liens brisés et les liens sur des pages redirigées, sur le site.
-f accéléré (fast), en réduisant l'attente du serveur. Par défaut 5 secondes, on peut définir le délai en ajoutant une valeur après -f.
-v verbeux, affiche tous les liens testé, avec le code d'en-tête trouvé.
Par défaut affiche seulement les erreurs.
-q quiet, silencieux, n'affiche rien.
The program produces a file called links.log, which contains all the results and will be saved under a different name if you want to save.
The results provided by the script are perfect. Sometimes the message "broken" appears when the page is available in the browser. This is because the response time or from the server is too long. In this case, it is enough to ignore the result.
Error messages and actions
When a script attempts to access a page, the server may return different code depending on the state of the page. It can be redirected either through a .htaccess file or through a PHP script, it may be absent.
200 OK. Page found.
301 Permanent redirection. The page is constantly redirected. Link needs to be changed.
400 bad requests. The syntax of the request is not understood by the server.
401 Unauthorized. Access denied.
403rd Zabidden. The server denies access to the script.
404 Page not found. Communication is broken.
500 internal server errors. Server problem.
Note that most often the program displays a message instead of an HTTP code:
Okay, that's 200.
The server problem URL is invalid. Try again later or remove the link.
Brocken. The code of the broken 404 link, delete it or find the page.
Redirect. Corresponds to 301, update link.
These different codes, other than the OK code, will not be counted until the page is available, except for persistent redirects that need to be updated.
For a complete list of codes and their meaning, see the HTTP Code document.
With the -s option, only the codes are considered:
404 Broken link.
301 When the redirected page is on the site itself.
Versions
- February 1.5, 2017. Page support in HTTPS.
- 1.4 February 2012. Error messages 302 (temporary redirection) are no longer displayed to reduce the list and are treated as 200 OK.
- 1.3 April 2011. Added -f option. Added exceptions to stop system messages and simplify display.
- 1.2. April 2011. Added -s option.
- 1.0. First version in 2008.
Obtaining a program and license
This review channel is licensed under the GNU GPL 2.0. You can use it free of charge and freely. If you distribute the archive, you must keep the copyright at the top of the Script and PHP source code.
Possible changes and improvements to the code should be provided in the form of open source Script and PHP, even if you are using a modified online program.
If PHP is not installed, you must load the interpreter in version 5 on the php.net.
- Download zip file,
- unpack it,
- open a command prompt window and
- execute the program in the window using the above command.
Free script under the GNU GPL 2.0 license
See also...
To cancel
For a static node only, check for broken links and redirects. In the second case, he replaces the URL with his new address.