Jump to content

I need help shorting my script


jet8791

Recommended Posts

i need help shorting this script asap

i need all the fsockopen's the combined into one and if the optional varables arnt set then dont include them.

i am willing to offer 10GB of online storage with unlimited bandwidth

 
//the variables
/*
$line[0] is the address
$line[1] is a port (required)
$line[2] is a port (optional)
$line[3] is a port (optional)
$line[4] is a port (optional)
*/
$fp = fsockopen ($line[0],$line[1], $errno, $errstr, 10);
    if (!$fp) {
    echo "<br><b>Checking $line[0]...</b><br>\n";
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Down, Domain: $line[0], Port: $line[1]</td>\n";
           echo "</tr>\n<tr>\n";
   echo "</tr></table>\n";
    } else {
        echo "<br><b>Checking $line[0]...</b><br>\n";
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Up, Domain: $line[0], Port: $line[1]$a</td>\n";
                   echo "</tr>\n<tr>\n";
   echo "</tr></table>\n";
    }
    fclose($fp);
    if($line[2] != ""){
$fp = fsockopen ($line[0], $line[2], $errno, $errstr, 10);
    if ($fp) {
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Up, Domain: $line[0], Port: $line[2]$a</td>\n";
                   echo "</tr>\n<tr>\n";
   echo "</tr></table>\n";
} else {
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Down, Domain: $line[0], Port: $line[2]$a</td>\n";
                   echo "</tr>\n<tr>\n";
   echo "</tr></table>\n";
    }
    fclose($fp);
}
if($line[3] != ""){
$fp = fsockopen ($line[0], $line[3], $errno, $errstr, 10);
    if ($fp) {
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Up, Domain: $line[0], Port: $line[3]$a</td>\n";
                   echo "</tr>\n<tr>\n";
   echo "</tr></table>\n";
} else {
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Down, Domain: $line[0], Port: $line[3]$a</td>\n";
                   echo "</tr>\n<tr>\n";
   echo "</tr></table>\n";
    }
    fclose($fp);
}
if($line[4] != ""){
$fp = fsockopen ($line[0], $line[4], $errno, $errstr, 10);
    if ($fp) {
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Up, Domain: $line[0], Port: $line[4]$a</td>\n";
                   echo "</tr>\n<tr>\n";
   echo "</tr></table>\n";
} else {
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
        echo "<td>Status: Down, Domain: $line[0], Port: $line[4]$a</td>\n";
                   echo "</tr>\n<tr>\n";
   echo "</tr></table>\n";
    }
    fclose($fp);
}

Link to comment
https://forums.phpfreaks.com/topic/36880-i-need-help-shorting-my-script/
Share on other sites

Dunno if this is what you are looking for, but it checks whether the required one is present and walks throug all - included optional ones

Not tested.


<?php

//the variables
/*
$line[0] is the address
$line[1] is a port (required)
$line[2] is a port (optional)
$line[3] is a port (optional)
$line[4] is a port (optional)
*/

$check = array_slice($line, 1);
if(!empty($line) && !empty($check)){
foreach($check as $port){

$fp = fsockopen ($line[0],$port, $errno, $errstr, 10);
    if (!$fp) {
    echo "<br><b>Checking $line[0]...</b><br>\n";
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
    echo "<td>Status: Down, Domain: $line[0], Port: $port</td>\n";
    echo "</tr>\n<tr>\n";
    echo "</tr></table>\n";
    }
    else {
    echo "<br><b>Checking $line[0]...</b><br>\n";
    echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000><tr>\n";
    echo "<td>Status: Up, Domain: $line[0], Port: {$port}$a</td>\n";
    echo "</tr>\n<tr>\n";
    echo "</tr></table>\n";
    }
fclose($fp);
}
}
else{
  echo "Required port is not selected";
}

?>

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.