Test Connection
Posted: Fri Oct 27, 2006 1:07 am
Using curl, is there a simple way for me to test if a connection to a website is succesful or not, and then have curl return a bool value?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$proxy = $_POST['proxy'];
$port = $_POST['port'];
$url = "http://www.paypal.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if(!empty($proxy)){
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy.':'.$port); //use proxy
}
curl_setopt ($ch, CURLOPT_TIMEOUT, 5);
$result = curl_exec ($ch);
$error = curl_errno($ch);
curl_close ($ch);
if($error == "0"){
echo "<b><font color='green'>Connection Succesful</font></b>";
} else {
echo "<b><font color='red'>Connection Failed</font></b>";
echo "<form method='post' action='conection.php'>
Enter a proxy address: <input type='test' name='proxy' /><br><br>
Enter a proxy port: <input type='test' name='port' /><br>
<input type='submit' class='button' value='Check Again' /></form>";
}
?>