WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 26128
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  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);

}

}

?>



redirect redirection ip address authentication authenticate addr
Categories : Authentication, HTTP, Network, PHP
Simple Password example
Categories : PHP, Authentication, Security, HTTP
Authentication HTTP protocol POST
Categories : Authentication, HTTP, PHP
A simple script to count and report hits and the last modification time of an HTML page. Requires MySQL support (other DBs should work too, except possibly mSQL).
Categories : HTTP, MySQL, PHP, Databases
Password using php, Javascript, and html form
Categories : Security, PHP, Authentication, Java Script
Protect your mailto: email addresses from bots - pure PHP
Categories : PHP, Email, Security
EAvalidator - This class can be used to validate an e-mail address by checking its domain.
Categories : PHP, PHP Classes, Email, Regexps
Solution to those 'tell-a-friend' type email issues
Categories : PHP, Email, Databases, MySQL
IP Blocking
Categories : PHP, Security, HTTP
phpEasyMail: An easy way to send data from HTML-forms via EMail.
Categories : Email, HTML and PHP, Complete Programs, PHP
header -- Send a raw HTTP header
Categories : PHP, PHP Functions, HTTP
How to let a user download a picture by clicking on it instead of needing to right click and Save-As.
Categories : HTTP, PHP, HTML and PHP, Filesystem
This gets the http response headers for a given url and returns them in an assoc array. i.e. to test if a url exists: $array = get_http_headers($url); if($array[result]=200) { }
Categories : HTTP, Arrays, PHP
Identify and log search engine access (spiders, robots, etc.) to a page.
Categories : HTTP, Environment Variables, PHP, MySQL, Databases
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
 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