note 51363 added to function.fsockopen

From: Date: Mon, 28 Mar 2005 22:38:12 +0000
Subject: note 51363 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-87110@lists.php.net to get a copy of this message
The following script will login to a POP3 account using the username, password and server name provided via a standard form; determine the amount of messages using a binary search; then purge all messages. <?php $server = $_POST["server"]; $user = $_POST["user"]; $pass = $_POST["pass"]; $count = 1; $low = 0; $mid = 0; $high = 100000; $connection = fsockopen($server, 110, $errno, $errstr, 30); if(!$connection) { print "Connect Failed: $errstr ($errno)"; } else { $output = fgets($connection, 128); fputs($connection, "user $user\n"); $output = fgets($connection, 128); fputs($connection, "pass $pass\n"); $output = fgets($connection, 128); while($low < $high - 1) { $mid = floor(($low + $high) / 2); fputs($connection, "list $mid\n"); $output = fgets($connection, 128); $subout = substr($output, 0, 4); if($subout == "+OK ") { $low = $mid; continue; } elseif($subout == "-ERR") { $high = $mid; continue; } else { break; print "An error has occurred. Please try again."; } } $limit = $mid - 1; while($count <= $limit) { fputs($connection, "dele $count\n"); fgets($connection, 128); $count = $count + 1; } fputs($connection, "quit\n"); } fclose($connection); print "Successfully removed $limit messages."; ?> ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51363 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51363&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51363&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51363&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51363&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51363&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51363&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87110) next »