Page 1 of 2

Tell if a URL is active or NOT

Posted: Mon Nov 26, 2007 1:56 pm
by psychotomus
how can I tell if a URL is active or not?

like devnetwork.net is active

asdlkfjasdkljk343kjadsf.com is not Active

Posted: Mon Nov 26, 2007 2:09 pm
by deadoralive
Could you use curl to try and fetch a page from the url in question?

Posted: Mon Nov 26, 2007 2:12 pm
by John Cartwright
cURL is probably your best bet, since you can control the timeout incase there is some latency. A simple alternative to cURL (since it can be a lot to swallow for beginers -- although I do suggest you try cURL first)

Code: Select all

if (@file_get_contents('http://domain.com')) {
   echo 'i can connect!';
} else {
   echo 'i cannot connect!';
}
fsockopen() and similar functions can also accomplish this quite easily as well.

Posted: Mon Nov 26, 2007 3:18 pm
by psychotomus
doesn't seem like file_get_contents is working... =(

http://po2upload.com/url_checker password = blind

Code: Select all

<?
session_start();
include 'config.php';

if(!isset($_SESSION['log']))
{
	if(isset($_POST['Submit']))
	{
		if($_POST['textPass'] == $pass)
		{
			$_SESSION['log'] = true;
		}
		else
		{
			echo 'Incorrect Password.';
		}
	}
?>
<form name="form1" method="post" action="">
  <input name="textPass" type="text" id="textPass">
  <br>
  <input type="submit" name="Submit" value="Login">
</form>
<?
}

if(isset($_SESSION['log']))
{
?>
<a href="index.php?action=add_link">Add Link</a> : <a href="index.php?action=check_links">Check Links</a> 
<?
	if($_GET['action'] == "add_link")
	{
		if(isset($_POST['Submit2']))
		{
			$title = $_POST['textTitle'];
			$url = $_POST['textURL'];
			mysql_query("INSERT INTO urls (url, title) VALUES ('$url', '$title')") or die(mysql_error());
			echo 'Title and URL added to database';
		}
?>
<form name="form2" method="post" action="">
  <table width="100%"  border="0">
    <tr>
      <td>Title:</td>
      <td><input type="text" name="textTitle"></td>
    </tr>
    <tr>
      <td>URL:</td>
      <td><input type="text" name="textURL"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit2" value="Add Link"></td>
    </tr>
  </table>
</form>
<?
	}
	elseif ($_GET['action'] == "check_links")
	{
		if(isset($_POST['Remove']))
		{
			//loop threw all selected items
			for($x =0; $x < count($_POST['hidden']);$x++)
			{
				if (isset($_POST['checkbox'][$x]))
				{
					//update cheat info
					mysql_query("DELETE FROM urls WHERE id='" . $_POST["hidden"][$x] . "'") or die(mysql_error());
				}
			}
			echo '<p>Title(s) And URL(s) Removed.</p>';
		}
?>
<form name="form3" method="post" action="">
<?
$result = mysql_query("SELECT * FROM urls");
while($urls = mysql_fetch_object($result))
{
	if (!(@file_get_contents($urls->url))) 
	{ 
?>

  <table width="100%"  border="0">
	<tr>
	  <td><?= $urls->title ?></td>
	</tr>
	<tr>
	  <td><div align="right">
	   <input name="hidden[<?= $counter ?>]" type="hidden" id="hidden[<?= $counter ?>]" value="<?= $urls->id ?>">
	   <input type="checkbox" name="checkbox[<?= $counter ?>]" value="remove">
	  </div></td>
	</tr>
  </table>

<?
	$counter = $counter +1;
	}
}
?>
<input type="submit" name="Remove" value="Remove">
</form>
<?
	}
}
?>

Posted: Mon Nov 26, 2007 3:33 pm
by Oren
fsockopen() sounds like a good solution for that.

Posted: Mon Nov 26, 2007 3:42 pm
by John Cartwright
Thinking about it, indeed you should use fsockopen since you don't actually want to retrieve the contents of the file and simply make a connection.

Try

Code: Select all

$fp = @fsockopen("domain.com", 80, $errno, $errstr, 30);
if (!$fp) {
   echo 'not connected';
} else {
	echo 'connected';
   fclose($fp);
}
Notice the 5th parameter is the timeout (in seconds), so you may want to adjust this accordingly.

Posted: Mon Nov 26, 2007 4:19 pm
by psychotomus
Still doesn't seem to work....

its showing all links as not being active.
even http://www.google.com

Code: Select all

<?
$result = mysql_query("SELECT * FROM urls");
while($urls = mysql_fetch_object($result))
{
	$fp = @fsockopen($urls->url,80, $errno, $errstr, 60);
	if (!$fp) 
	{ 
?>

  <table width="100%"  border="0">
	<tr>
	  <td><?= $urls->title ?></td>
	</tr>
	<tr>
	  <td><div align="right">
	   <input name="hidden[<?= $counter ?>]" type="hidden" id="hidden[<?= $counter ?>]" value="<?= $urls->id ?>">
	   <input type="checkbox" name="checkbox[<?= $counter ?>]" value="keep">
	  </div></td>
	</tr>
  </table>

<?
	$counter = $counter +1;
	}
	else
	{
		fclose($fp);
	}
}
?>
<input type="submit" name="Remove" value="Remove">
</form>
<?
	}
}
?>

Posted: Mon Nov 26, 2007 4:24 pm
by John Cartwright
Please add

Code: Select all

var_dump($urls->url);
above the fsockopen() call and post the output

Posted: Mon Nov 26, 2007 4:59 pm
by s.dot
do you have allow_url_fopen on?

Code: Select all

var_dump($a = ini_get('allow_url_fopen'));

Posted: Mon Nov 26, 2007 4:59 pm
by psychotomus
string(37) "http://video.stage6.com/1893852/.divx"
working test

string(22) "www.comerzzzzzzzzz.com"
faled test

string(36) "www.penissszzzzzzzzRRrrrrrrrrrrr.org"
aaa

string(37) "http://video.stage6.com/1893852/.divx"
asdfasdfa

string(22) "http://www.teampo2.com"
kkk

string(21) "http://www.google.com"
Google

Posted: Mon Nov 26, 2007 5:00 pm
by psychotomus
scottayy wrote:do you have allow_url_fopen on?

Code: Select all

var_dump($a = ini_get('allow_url_fopen'));


string(1) "1"


i guess its on?

Posted: Mon Nov 26, 2007 5:00 pm
by s.dot
Yes, it is.

Posted: Mon Nov 26, 2007 5:04 pm
by s.dot
That's interesting. I have no idea, actually.

Perhaps this can help you: http://us3.php.net/manual/en/function.f ... .php#75388 (it's doing the same thing with http and https protocols)

Posted: Mon Nov 26, 2007 5:13 pm
by John Cartwright
Try replacing your while loop with this following, this should shed light to why the connections are failing.

Code: Select all

<?
$result = mysql_query("SELECT * FROM urls");
while($urls = mysql_fetch_object($result))
{
	$fp = @fsockopen($urls->url, 80, $errno, $errstr, 30);
	if (!$fp) {
		echo 'Cannot connect to "'. $urls->url .'. Reason: '. $errstr .'" <br />';
	} else {
		echo 'Connected to "'. $urls->url .'" <br />';
		fclose($fp);
	}
}
?>
[/quote]

Posted: Mon Nov 26, 2007 5:16 pm
by psychotomus
Cannot connect to "http://video.stage6.com/1893852/.divx. Reason: Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?"
Cannot connect to "www.comerzzzzzzzzz.com. Reason: "
Cannot connect to "www.penissszzzzzzzzRRrrrrrrrrrrr.org. Reason: "
Cannot connect to "http://video.stage6.com/1893852/.divx. Reason: Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?"
Cannot connect to "http://www.teampo2.com. Reason: Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?"
Cannot connect to "http://www.google.com. Reason: Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?"