Page 1 of 1

Check If URL is Online

Posted: Mon Feb 23, 2015 1:21 am
by hillchris84
Script URL: LinkMan
Version of script: 171
Hosting company: GoDaddy
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: URL Online

Write your message below:
Hello new to the forum, anyway love the PHP script! I have been trying to figure out a way to display if the URL or Link in the list is either Up (online) or Down (offline). I have the following PHP script to do so, however I cannot seem to find a good solution for displaying it to all links submitted. Any ides would be appreciated! Here is the code:

<?
/**
* Function to check a website status
* @param string url the url of the website to test
* @return boolean true if the site is up, false otherwise
*/

function checkStatus($url){
$agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; pt-pt) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";

// initializes curl session
$ch=curl_init();

// sets the URL to fetch
curl_setopt ($ch, CURLOPT_URL,$url );

// sets the content of the User-Agent header
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

// return the transfer as a string
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

// disable output verbose information
curl_setopt ($ch,CURLOPT_VERBOSE,false);

// max number of seconds to allow cURL function to execute
curl_setopt($ch, CURLOPT_TIMEOUT, 5);

curl_exec($ch);

// get HTTP response code
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if($httpcode>=200 && $httpcode<300)
return true;
else
return false;
}

if(checkStatus("http://test.com"))
echo '<img src="green.png" title="Up" alt="Up" />';
else
echo '<img src="red.png" title="Down" alt="Down" />';

if(checkStatus("http://test.com"))
echo '<img src="green.png" title="Up" alt="Up" />';
else
echo '<img src="red.png" title="Down" alt="Down" />';
?>