Jump to content

[SOLVED] fsockopen and subdirectories


boemboem

Recommended Posts

After some testing also from this phpfreaks (thank you for that), there are some problems wich accur when people submit a url with a /subdirectory in it.

The sit is alive, but it shows not alive because it can't find a index.* page I believe.

 

This is the output page and the code: http://keurmerk.coldcharlie.nl/multi.php

<?php

//Fill this in with the list of servers
$servers = file('./text.txt');

// Function to check response time
function pingDomain($domain){
    $starttime = microtime(true);
    $file      = @fsockopen ($domain, 80, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;  // Site is down
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 1000;
        $status = floor($status);
    }
    return $status;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<body>
  <table>
<?php    
  foreach($servers as $domainbase){
    $status = pingDomain(trim($domainbase));
    if ($status != -1)
      echo "<tr><td><img src=\"images/status/alive.gif\" /> <b><a href=\"http://$domainbase\" target=\"_blank\">http://$domainbase</a></td><tr>";
    else
      echo "<tr><td><img src=\"images/status/dead.gif\" /> <b><a href=\"http://$domainbase\" target=\"_blank\">http://$domainbase</a></td><tr>";
  }
?>
</table>
</body>
</html>

 

This is the form handler: http://keurmerk.coldcharlie.nl/form.html

<?PHP

###################### Set up the following variables ######################
# #
$filename = "text.txt"; #CHMOD to 666
$forward = 0; # redirect? 1 : yes || 0 : no
$location = "thankyou.htm"; #set page to redirect to, if 1 is above
# #
##################### No need to edit below this line ######################

$msg .= $_POST['url'] . "\n";
$fp = fopen ($filename, "a"); # w = write to the file only, create file if it does not exist, discard existing contents
if ($fp) {
fwrite ($fp, $msg);
fclose ($fp);
}
else {
$forward = 2;
}

if ($forward == 1) {
//header ("Location:$location");
header("Location: " . $_SERVER['HTTP_REFERER']);
}
else if ($forward == 0) {
echo ("Thank you for submitting our form. We will get back to you as soon as possible.");
}
else {
"Error processing form. Please contact the webmaster";
}

?>

 

Any help would be great

 

I found something here: http://www.webmasterworld.com/forum88/77.htm I dont understand ehat they mean :)

 

Link to comment
https://forums.phpfreaks.com/topic/140672-solved-fsockopen-and-subdirectories/
Share on other sites

try this:

<?php

//Fill this in with the list of servers
$servers = file('./text.txt');

// Function to check response time
function pingDomain($domain){
  $host = parseurl($domain,PHP_URL_HOST);
  
  $starttime = microtime(true);
  $file      = @fsockopen ($host, 80, $errno, $errstr, 10);
  $stoptime  = microtime(true);
  $status    = 0;

  if (!$file) $status = -1;  // Site is down
  else {
    fclose($file);
    $status = ($stoptime - $starttime) * 1000;
    $status = floor($status);
  }
  return $status;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<body>
  <table>
<?php    
  foreach($servers as $domainbase){
    $status = pingDomain(trim($domainbase));
    if ($status != -1)
      echo "<tr><td><img src=\"images/status/alive.gif\" /> <b><a href=\"http://$domainbase\" target=\"_blank\">http://$domainbase</a></td><tr>";
    else
      echo "<tr><td><img src=\"images/status/dead.gif\" /> <b><a href=\"http://$domainbase\" target=\"_blank\">http://$domainbase</a></td><tr>";
  }
?>
</table>
</body>
</html>

ok, that worked, only the ouput is all negative now

 

http://keurmerk.coldcharlie.nl/multi.php

 

<?php

//Fill this in with the list of servers
$servers = file('./text.txt');

// Function to check response time
function pingDomain($domain){
  $host = parse_url($domain,PHP_URL_HOST);
  
  $starttime = microtime(true);
  $file      = @fsockopen ($host, 80, $errno, $errstr, 10);
  $stoptime  = microtime(true);
  $status    = 0;

  if (!$file) $status = -1;  // Site is down
  else {
    fclose($file);
    $status = ($stoptime - $starttime) * 1000;
    $status = floor($status);
  }
  return $status;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<body>
  <table>
<?php    
  foreach($servers as $domainbase){
    $status = pingDomain(trim($domainbase));
    if ($status != -1)
      echo "<tr><td><img src=\"images/status/alive.gif\" /> <b><a href=\"http://$domainbase\" target=\"_blank\">http://$domainbase</a></td><tr>";
    else
      echo "<tr><td><img src=\"images/status/dead.gif\" /> <b><a href=\"http://$domainbase\" target=\"_blank\">http://$domainbase</a></td><tr>";
  }
?>
</table>
</body>
</html>

ok...this should work now:

<?php

//Fill this in with the list of servers
$servers = file('./text.txt');

// Function to check response time
function pingDomain($host){
  $starttime = microtime(true);
  $file      = @fsockopen ($host, 80, $errno, $errstr, 10);
  $stoptime  = microtime(true);
  $status    = 0;

  if (!$file) $status = -1;  // Site is down
  else {
    fclose($file);
    $status = ($stoptime - $starttime) * 1000;
    $status = floor($status);
  }
  return $status;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<body>
  <table>
<?php    
  foreach($servers as $domainbase){
    $host = parse_url(trim($domainbase),PHP_URL_HOST);
    $status = pingDomain($host);
    if ($status != -1)
      echo "<tr><td><img src=\"images/status/alive.gif\" /> <b><a href=\"$domainbase\" target=\"_blank\">$domainbase</a></td><tr>";
    else
      echo "<tr><td><img src=\"images/status/dead.gif\" /> <b><a href=\"$domainbase\" target=\"_blank\">$domainbase</a></td><tr>";
  }
?>
</table>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.