首先假设一下条件:
Your Proxy server for pop/imap is running on 192.168.1.1
You have 2 backend pop/imap servers: 192.168.1.22 and 192.168.1.33
You have a webserver that you will use for the authentication and redirection logic 192.168.1.44.
Gyb2b V1.01免费版可终身使用,是一款功能强大的B2B电子商务应用软件。该软件不仅更新和修改了V1.0相关功能,更是采用了目前互联网上最流行的LAMP组合(Linux+Apache+Mysql+PHP)开发完成,模板技术实现了界面与代码的有效分离,用户可以快速地在此基础上编译模板;提供B2B电子商务应用最常见的求购、供应、商品、公司库、行业资讯、商圈、资信认证、在线交易、交易评分、留言、搜
0
The authentication script is /mail/auth.php
立即学习“PHP免费学习笔记(深入)”;
<?php
if (!isset($_SERVER["HTTP_AUTH_USER"] ) || !isset($_SERVER["HTTP_AUTH_PASS"] )){
fail();
}
$username=$_SERVER["HTTP_AUTH_USER"] ;
$userpass=$_SERVER["HTTP_AUTH_PASS"] ;
$protocol=$_SERVER["HTTP_AUTH_PROTOCOL"] ;
// default backend port
$backend_port=110;
if ($protocol=="imap") {
$backend_port=143;
}
if ($protocol=="smtp") {
$backend_port=25;
}
// nginx likes ip address so if your
// application gives back hostname, convert it to ip address here
$backend_ip["mailhost01"] ="192.168.1.22";
$backend_ip["mailhost02"] ="192.168.1.33";
// Authenticate the user or fail
if (!authuser($username,$userpass){
fail();
exit;
}
// Get the server for this user if we have reached so far
$userserver=getmailserver($username);
// Get the ip address of the server
// We are assuming that you backend returns hostname
// We try to get the ip else return what we got back
$server_ip=(isset($backend_ip[$userserver] )?$backend_ip[$userserver] :$userserver;
// Pass!
pass($server_ip, $backend_port);
//END
function authuser($user,$pass){
// put your logic here to authen the user to any backend
// you want (datbase, ldap, etc)
// for example, we will just return true;
return true;
}
function getmailserver($user){
// put the logic here to get the mailserver
// backend for the user. You can get this from
// some database or ldap etc
// dummy logic, all users that start with a,c,f and g get mailhost01
// the others get mailhost02
if in_array(substr($user,0,1), array("a","c","f","g")){
return"mailhost01";
} else {
return"mailhost02";
}
}
function fail(){
header("Auth-Status: Invalid login or password");
exit;
}
function pass($server,$port){
header("Auth-Status: OK");
header("Auth-Server: $server");
header("Auth-Port: $port");
exit;
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号