₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,346,594 members, 8,524,059 topics. Date: Tuesday, 24 November 2026 at 11:33 AM

Toggle theme

Explanation Needed In PHP - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Explanation Needed In PHP (1107 Views)

1 Reply (Go Down)

Explanation Needed In PHP by paranorman(op): 5:16pm On Jun 11, 2017
 //give te script time to execute
ini_set("max_execution_time", 200);

$portRange = range(0, 1023);
$host = "127.0.0.1";

print "<p>The scan results for $host is:</p>";
//execute the scan
foreach ($portRange as $port) {
if ($result = @fsockopen($host, $port, $errNo, $errString, 1)) {
$service = getservbyport($port, 'tcp');
print "Socket open at port $port, with <em><strong>$service</strong></em> service <br />";
}
} //end loop


The code above works just fine because wrote '@' beside the fsockopen() function. Removing the '@' produces error as seen in the screen shots. Why is the @ compulsory? what it actually does?

Thanks in anticipation of your replies.

Re: Explanation Needed In PHP by Caustics: 5:19pm On Jun 11, 2017
cool
Re: Explanation Needed In PHP by Echatbook: 6:21pm On Jun 11, 2017
paranorman:
 //give te script time to execute
ini_set("max_execution_time", 200);

$portRange = range(0, 1023);
$host = "127.0.0.1";

print "<p>The scan results for $host is:</p>";
//execute the scan
foreach ($portRange as $port) {
if ($result = @fsockopen($host, $port, $errNo, $errString, 1)) {
$service = getservbyport($port, 'tcp');
print "Socket open at port $port, with <em><strong>$service</strong></em> service <br />";
}
} //end loop


The code above works just fine because wrote '@' beside the fsockopen() function. Removing the '@' produces error as seen in the screen shots. Why is the @ compulsory? what it actually does?

Thanks in anticipation of your replies.
Basically using the @sign will cause all php warnings not to be shown for that particular function.
Re: Explanation Needed In PHP by nsimageorge(m): 6:48pm On Jun 11, 2017
http://php.net/manual/en/language.operators.errorcontrol.php

Like Echatbook said, the @silences errors for a function(read the php manual above)

If you don't mind me asking what exactly whee you trying to achieve with your function. It would be best to write a bug free code.
Re: Explanation Needed In PHP by paranorman(op): 8:09pm On Jun 11, 2017
I appreciate your contributions. Thanks
1 Reply

I Need Online Banking Source Code In PHP, MSQL • Online Banking Source Code In PHP, MSQL • 2 • 3 • 4

My Programming Park (rise Of A Learner) • E Commerce Programming • Bitcoin Mining $ 1 Every Day