Forum Moderators: coopster

Message Too Old, No Replies

pop3 authentication function failing

         

ahmed24

9:59 am on Aug 23, 2009 (gmt 0)

10+ Year Member



i have the following function that validates a username and password against a pop3 server. but it seems to not work and the entire php page returns nothing. can anyone have a look an possibly suggest what could be wrong? thanks

function auth_pop3($username, $password, $popserver){

if(trim($username)='') {
return false;
} else {
$fp = fsockopen("$popserver", 110, &$errno, &$errstr);
if(!$fp) {
// failed to open POP3
return false;
} else {
set_socket_blocking($fp,-1); // Turn off blocking

$trash = fgets($fp,128); // Trash to hold the banner

fwrite($fp,"USER $username\r\n"); // POP3 USER CMD

$user = fgets($fp,128);
$user = ereg_replace("\n","",$user);

if ( ereg ("^\+OK(.+)", $user ) ) {

fwrite($fp,"PASS $password\r\n"); // POP3 PASS CMD
$pass = fgets($fp,128);
$pass = ereg_replace("\n","",$pass);

if ( ereg ("^\+OK(.+)", $pass ) ) {
// User has successfully authenticated
$auth = true;
} else {
// bad password
$auth = false;
}

} else {
// bad username
$auth = false;
}
fwrite($fp,"QUIT\r\n");
fclose($fp);
return $auth
}
}
}

ahmed24

6:00 pm on Aug 23, 2009 (gmt 0)

10+ Year Member



anyone?