Tell if a URL is active or NOT
Moderator: General Moderators
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
Tell if a URL is active or NOT
how can I tell if a URL is active or not?
like devnetwork.net is active
asdlkfjasdkljk343kjadsf.com is not Active
like devnetwork.net is active
asdlkfjasdkljk343kjadsf.com is not Active
-
deadoralive
- Forum Commoner
- Posts: 28
- Joined: Tue Nov 06, 2007 1:24 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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)
fsockopen() and similar functions can also accomplish this quite easily as well.
Code: Select all
if (@file_get_contents('http://domain.com')) {
echo 'i can connect!';
} else {
echo 'i cannot connect!';
}-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
doesn't seem like file_get_contents is working... =(
http://po2upload.com/url_checker password = blind
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> </td>
<td> </td>
</tr>
<tr>
<td> </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>
<?
}
}
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
Notice the 5th parameter is the timeout (in seconds), so you may want to adjust this accordingly.
Try
Code: Select all
$fp = @fsockopen("domain.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo 'not connected';
} else {
echo 'connected';
fclose($fp);
}-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
Still doesn't seem to work....
its showing all links as not being active.
even http://www.google.com
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>
<?
}
}
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Please add
above the fsockopen() call and post the output
Code: Select all
var_dump($urls->url);do you have allow_url_fopen on?
Code: Select all
var_dump($a = ini_get('allow_url_fopen'));Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
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
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"
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
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?
Yes, it is.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
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)
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)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Try replacing your while loop with this following, this should shed light to why the connections are failing.
[/quote]
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);
}
}
?>-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
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?"
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?"