PHPverse 2025

Voting

: max(eight, one)?
(Example: nine)

The Note You're Voting On

v13+phpnet at it dot teithe dot gr
18 years ago
The following function performs pop3 authentication. Returns NULL on error, or true/false to indicate username/password matching:

$address is the hostname of the server and $ssl is a boolean that indicates whether an SSL connection is requested.

<?php
function pop3authCheck($username, $password, $address, $ssl)
{
if (
$ssl)
$uri="ssl://$address:995";
else
$uri="tcp://$address:110";

$fp=fsockopen($uri);

if (!
$fp)
return(
NULL);

$st=fgets($fp, 512);
if (
substr($st, 0, 3)!="+OK")
{
fclose($fp);
return(
NULL);
}

$st="USER $username\n";
if (
fwrite($fp, $st)!=strlen($st))
{
fclose($fp);
return(
NULL);
}

$st=fgets($fp, 512);
if (
substr($st, 0, 3)!="+OK")
{
fclose($fp);
return(
NULL);
}

$st="PASS $password\n";
if (
fwrite($fp, $st)!=strlen($st))
{
fclose($fp);
return(
NULL);
}

$st=fgets($fp, 512);
fclose($fp);
if (
substr($st, 0, 3)=="+OK")
return(
true);
else if (
substr($st, 0, 4)=="+ERR")
return(
false);
else
return(
NULL);
}
?>

<< Back to user notes page

To Top