First of all create a .php file (link-checker.php).
Add the PHP start tag <?php.
Now create a variable, $website and assign the link to it. The link must be http://www.domain.tld.
Create another variable, $works and assign it with @fsockopen($website, $port, $errno, $errstr, $timeout).
We are using the fsockopen function (Initiates a socket connection to the resource specified) with:
-$website (the hostname)
-$port (the port number, 80)
-$errno (If provided, holds the system level error number that occurred in the system-level connect() call. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket.)
-$errstr (the error message as a string)
-$timeout (the connection timeout in seconds, 30).
After doing that, we will use the if statement. If $works is true, it means that the link is still working and it will return the message http://www.itstart.org works fine!, with an anchor to itstart. If $works is not true, it means that the link is no longer working and it will return the message http://www.itstart.org is down. We'll be right back!, also with an anchor to itstart.
That's it! Now you've created a checking links script using PHP! Congrats!
Here is the full code:
- Cod: Selectaţi tot
<?php
$website = 'www.itstart.org';
$port = 80;
$timeout = 30;
$works = @fsockopen($website, $port, $errno, $errstr, $timeout);
if($merge) {
echo ''.$site.' works fine!';
} else {
echo ''.$site.' is down. We'll be right back!';
}
?>
Note: You can change http://www.itstart.org with the link you want to check and run the file on a host. Enjoy!




