Test Connection
Moderator: General Moderators
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
Test Connection
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?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
well actually its going to be connecting to a secure site so i believe we would be testing a connection to 443(?) is that still possable with fsockopen() ? Also in the event a connection fails, the user will be prompted to enter a proxy address and then retest the connection. Can fsockopen use a proxy to connect?
I should of added this in my first post, sry
I should of added this in my first post, sry
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
I slept on it and came up with this:
works like a charm 
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>";
}
?>