note 51870 added to ref.sockets

From: Date: Wed, 13 Apr 2005 13:33:08 +0000
Subject: note 51870 added to ref.sockets
Groups: php.notes 
Request: Send a blank email to php-notes+get-87952@lists.php.net to get a copy of this message
There's a bug on the samples for this page. socket_connect does not return a negative number in case of error, it returns a boolean, that is, non-zero means it worked, zero means there was an error. There's a sample that can be usefull. It's a primitive portscanner: <html> <body> <h1>Socket Test (Portscanner)</h1> <?php error_reporting (E_ERROR); $address = gethostbyname ('localhost'); $socket = socket_create (AF_INET, SOCK_STREAM, 0); if ($socket < 0) { echo "Can't create the socket: " . socket_strerror ($socket) . "\n"; } $result = socket_connect ($socket, $address, 80); if ($result) { echo "Open port: 80<br>"; } else { echo "Closed port: 80<br>"; } socket_close ($socket); ?> </body> </html> ---- Manual Page -- http://www.php.net/manual/en/ref.sockets.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51870 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51870&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51870&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51870&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51870&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51870&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51870&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87952) next »