note 40360 added to function.fsockopen

From: Date: Mon, 01 Mar 2004 11:42:49 +0000
Subject: note 40360 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-66029@lists.php.net to get a copy of this message
<?php function user_authenication($protocol,$username,$password, $server_domain_name,$server_port_number,$server_timeout_seconds=10) { // Licenced under the Lesser GNU Public Licence [LGPL] chalkta at yahoo dot com // Orginally posted on http://www.php.net/manual/en/function.fsockopen.php // Please retain this header in the case of implementation, modification // and/or redistribution. //Pre: The protocol variable will have one of the following // values: ftp, imap4 or pop3 The server_timeout_seconds // will be a positive number. //Post: Returns the string "Successful authenication." // if successful username and password credentials // are found. Otherwise, returns a string defining // the reason of the failure. $buffer_length = 1024; if(!(strtolower($protocol)=='ftp'||strtolower($protocol)=='imap4' ||strtolower($protocol)=='pop3')) { return "No valid authenication protocol has been specified ". "for the user_authenication function of this web application.";} $fp = @fsockopen($server_domain_name, $server_port_number, $errno, $errstr, $server_timeout_seconds); if (!$fp) { $authenication_state = 'Connection Timed Out.'; } else { switch(strtolower($protocol)) { case 'ftp': case 'pop3': $login_user_string = "USER $username\r\n"; $login_pass_string = "PASS $password\r\n"; $quit_string = "QUIT\r\n"; break; case 'imap4': $login_user_string = "1 LOGIN $username $password\r\n"; $quit_string = "1 LOGOUT\r\n"; break; } fputs($fp, $login_user_string); stream_set_timeout($fp, $server_timeout_seconds); if(!feof($fp)) { $return_string1 = fgets($fp, $buffer_length); } if(strstr(strtolower($return_string1), strtolower(strtolower($protocol)))) { switch(strtolower($protocol)) { case 'ftp': case 'pop3': fputs($fp, $login_pass_string); if(!feof($fp)) { $return_string2 = fgets($fp, $buffer_length); } break; } while (!feof($fp)) { $return_string3 = fgets($fp, $buffer_length); switch(strtolower($protocol)) { case 'ftp': $authenication_success = strstr(strtolower($return_string3) ,'230'); $authenication_failure = strstr(strtolower($return_string3) ,'530'); break; case 'imap4': $authenication_success = strstr(strtolower($return_string3),'authenticated'); $authenication_failure = strstr(strtolower($return_string3) ,'failed'); break; case 'pop3': $authenication_success = strstr(strtolower($return_string3) ,'ok'); $authenication_failure = strstr(strtolower($return_string3) ,'bad login'); break; default: $authenication_state = false; } if($authenication_success) { $authenication_state = 'Successful Authenication.'; } if($authenication_failure) { $authenication_state = 'Access Denied.'; } break; } } else { $authenication_state = 'Unidentified protocol.'; } fputs($fp, $quit_string); fclose($fp); } switch($authenication_state) { case 'Successful Authenication.': return 'Successful Authenication.'; break; case 'Connection Timed Out.': return "The ".strtoupper($protocol)." authenication server at " ."$server_domain_name:$server_port_number is down. $errstr."; break; case 'Unidentified protocol.': return "Unable to identified the connected ".strtoupper($protocol) ." authenication server port of $server_port_number at " ."$server_domain_name as the ".strtoupper($protocol)." protocol."; break; case 'Access Denied.': default: return 'Access Denied.'; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40360 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40360&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40360&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66029) next »