WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : HTTP Basic Authentication via POP3.
Categories : Authentication, HTTP, Email, PHP Update Picture
Joe H
Date : Oct 06th 1998
Grade : 5 of 5 (graded 1 times)
Viewed : 18885
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Joe H
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
/*

HTTP Basic Authentication using POP3

POP servers should be RFC 1939 Compliant and return
'+OK <whatever>' on success and '-ERR <whatever>' on failure.

YMMV of course.

I don't support this, don't ask me questions, yadda yadda
All this script does is authenticate - what you do from there
is up to you. I just really didn't want system password files
used for web authentication - which is a "Really Bad Idea".

Public Domain Source code - use as you see fit.

05-Oct-1998
joe@blarg.net


*/

$REALM = "My Realm";
$POPSERVER = 'pop3.yourdomain.com'; // Change this, please.

$LOGERRORS = 1; // Comment this line out to NOT log
// Authentication errors.
// Logs to STDERR - could use syslog
// with minor tweaking.

if(!isset($PHP_AUTH_USER)) {
Header("WWW-Authenticate: Basic realm=\"$REALM\"");
Header("HTTP/1.0 401 Unauthorized");
echo "<H1>Authorization Required</H1>\n";
exit;
} else {
$fp = fsockopen("$POPSERVER", 110, &$errno, &$errstr);
if(!$fp) {
if (isset($LOGERRORS)) {
error_log("AUTH ERROR ($PHP_AUTH_USER/$PHP_AUTH_PW) Connection Failure",0);
error_log("POP3 ERROR [$errno] [$errstr]",0);
}
Header("WWW-Authenticate: Basic realm=\"$REALM\"");
Header("HTTP/1.0 401 Auth Required");
echo "<H1>Authorization Required</H1>\n";
exit;
} else {

set_socket_blocking($fp,-1); // Turn off blocking

/*
Clear the POP server's Banner Text.
eg.. '+OK Welcome to <server name> etc etc'
*/

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

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

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

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

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

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




// User has successfully authenticated

echo "<BR>Authenticated: $pass<BR>\n";

if (isset($LOGERRORS)) {
error_log("AUTH OK: $PHP_AUTH_USER",0);
}


} else {
if (isset($LOGERRORS)) {
error_log("AUTH ERROR ($PHP_AUTH_USER/$PHP_AUTH_PW)",0);
error_log("POP3 ERROR $pass",0);
}
Header("WWW-Authenticate: Basic realm=\"$REALM\"");
Header("HTTP/1.0 401 Auth Required");
echo "<H1>Authorization Required</H1>\n";
exit;
}

} else {
if (isset($LOGERRORS)) {
error_log("AUTH ERROR ($PHP_AUTH_USER/$PHP_AUTH_PW)",0);
error_log("POP3 ERROR [$user]",0);
}
Header("WWW-Authenticate: Basic realm=\"$REALM\"");
Header("HTTP/1.0 401 Auth Required");
echo "<H1>Authorization Required</H1>\n";
exit;
}

fwrite($fp,"QUIT\r\n");
fclose($fp);

}

}

?>



Simple Password example
Categories : PHP, Authentication, Security, HTTP
Authentication HTTP protocol POST
Categories : Authentication, HTTP, PHP
redirect redirection ip address authentication authenticate addr
Categories : Authentication, HTTP, Network, PHP
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate.
Categories : Authentication, PHP
simple script to send emails via a html-form to different users
Categories : Email, MySQL, PHP, Databases
The following snippet gives complete info about all submitted HTTP_POST_VARS and HTTP_GET_VARS
Categories : Variables, HTTP, PHP
Email a user with out exposing email address
Categories : PHP, Databases, MySQL, Email
PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character.
Categories : PHP, Algorithms, Security, Authentication, Encryption
Complete, simple working example of login screen and check on a unique page using php functions, cookies and mysql database.
Categories : PHP, Cookies, MySQL, HTML and PHP, Authentication
header -- Send a raw HTTP header
Categories : PHP, PHP Functions, HTTP
Broadcast HTML Email
Categories : PHP, Email, MySQL, Databases
POP3 Class
Categories : PHP Classes, PHP, Email
PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL
Function to remember password
Categories : PHP, Authentication, Personalization and Membership
 Paul Simpson wrote : 25
This code works a treat..
Thanks Ever so much
 
 Kyle Geddes wrote : 30
Sweet Code! - Do you have any examples of how to 
actually impliment this for a large site?
 
 Tony Chamberlain wrote : 301
Just wanted to say I have been using this code for a 
while now, works great! Highly recommended
 
 Prachya Pantuyakorn wrote : 602
Hi, I`ve tested ur script. It`s very useful. Would u pls give me and idea to create mailbox by using php cript? 

Best regard,
Prachya
 
 Tal Eilon wrote :629
Script works great! thanks a lot!!!!

--Tal