Hi this is my first post 😃 but anyway...
So I'm not new to running PHP's, I run about 4 sites on an OS X Server and every pages is a php, at minimum using traffic tracking software, at most, I have pages that use vB forums as news portals and all that good stuff. So I'm certainly not new to PHP, just new to writing my own. So I'm making a script that scans the visitors ports and alerts them if any are open (not all ports, just a standard basic security check type thing). Now so far I'm up to 11 ports but I'm sure I'll be adding more. So originally I had the same 11 blocks of code, one for each port. Once I got it working, I decided to put the code in a function and just call it, sending it the port number, each time. Standard stuff. The problem is, when I use the function to check the ports, I get errors for each. Not a "couldn't connect" or a "timeout" error, and error of type 0, which is described as an error that happens before it even tries to connect to a port. The code hasn't changed, just putting it in a function seems to disable it. I don't understand this but I hope its an easy one. Here is my function code.
<? function sniff( $portnumber ) {
if ( $sock = fsockopen($REMOTE_ADDR,$portnumber,$errno,$errstr,7) )
{
echo "<font color=#ff3300>Open</font>";
fclose($sock);
}
else
{
if ($errno == 60)
{
echo "Timeout";
}
else
{
echo "Closed $errno";
}
}
} ?>
And here is what I use to call this function:
<? sniff(22); ?>
Seems perfect to me??
And don't worry about the 7 second timeout, I'm testing it only on my LAN, and it loads instantly, and when I had it the other way (no function, that code duplicated 11 times), it also worked perfectly, and instantly, so the 7 seconds ain't it unless there's something I don't know going on.