Discuz教程网

重新封装zend_soap实现http连接安全认证的php代码

[复制链接]
authicon dly 发表于 2011-1-13 21:15:44 | 显示全部楼层 |阅读模式
代码如下:

  1. <?php
  2. class MyFramework_Soap_server extends Zend_Soap_Server {
  3. protected $_login = \'\';
  4. protected $_password = \'\';
  5. public function __construct($wsdl = null, array $options = null) {
  6. parent::__construct($wsdl,$options);
  7. if(isset($options[\'login\'])){
  8. $this->_login=$options[\'login\'];
  9. $this->_password=$options[\'password\'];
  10. $this->_authenticate();
  11. }
  12. }
  13. private function _authenticate(){
  14. $this->setAuthenticate($this->_login,$this->_password);
  15. }
  16. public function setHttpLogin($login){
  17. $this->_login=$login;
  18. }
  19. public function setHttpPassword($password){
  20. $this->_password=$password;
  21. if(isset($this->_login)){
  22. $this->_authenticate();
  23. }
  24. }
  25. public function setAuthenticate($login,$password){
  26. if ($_SERVER[\'PHP_AUTH_USER\']!=$login || $_SERVER[\'PHP_AUTH_PW\']!=$password) {
  27. header(\'WWW-Authenticate: Basic realm="MyFramework Realm"\');
  28. header(\'HTTP/1.0 401 Unauthorized\');
  29. echo "You must enter a valid login ID and password to access this resource.\\n";
  30. exit;
  31. }
  32. }
  33. }
  34. ?>
复制代码
  1. <?php
  2. class Soap_server_test {
  3. public $view = \'\';
  4. public $params = \'\';
  5. public $requestObj = \'\';
  6. public $dbObj = \'\';
  7. function __construct() {
  8. $this->view = $GLOBALS[\'view\'];
  9. $this->params = $GLOBALS[\'params\'];
  10. $this->requestObj = $GLOBALS[\'requestObj\'];
  11. $this->dbObj = $GLOBALS[\'dbObj\'];
  12. }
  13. function indexAction(){
  14. if(isset($_GET[\'wsdl\'])) {
  15. $autodiscover = new MyFramework_Soap_AutoDiscover();
  16. $autodiscover->setClass(\'Model_Service_SoapClassSetTest\');
  17. $autodiscover->handle();
  18. exit;
  19. } else {
  20. //$options= array(\'encoding\' => \'UTF-8\',\'login\'=>\'tangjian\',\'password\'=>\'123456\');
  21. $options= array(\'encoding\' => \'UTF-8\');
  22. $soap = new MyFramework_Soap_Server("http://tj.MyFramework.com/default/soap_server_test/index?wsdl",$options);
  23. $soap->setHttpLogin(\'tangjian\');
  24. $soap->setHttpPassword(\'123456\');
  25. $soap->setClass(\'Model_Service_SoapClassSetTest\');
  26. $soap->handle();
  27. exit;
  28. }
  29. }
  30. function clientAction() {
  31. //$options= array(\'encoding\' => \'UTF-8\',\'login\'=>\'tangjian\',\'password\'=>\'123456\',
  32. // \'compression\' =>SOAP_COMPRESSION_GZIP);
  33. $options= array(\'encoding\' => \'UTF-8\',
  34. \'compression\' =>SOAP_COMPRESSION_GZIP);
  35. $client = new MyFramework_Soap_Client(\'http://tj.MyFramework.com/default/soap_server_test/index?wsdl\',$options);
  36. $client->setHttpLogin(\'tangjian\');
  37. $client->setHttpPassword(\'123456\');
  38. $result=$client->getPass(\'tang\',"man");
  39. print_r($result);
  40. }
  41. }
  42. ?>
复制代码






上一篇:php之数据库密码的找回
下一篇:php 变量未定义等错误的解决方法
authicon huanglv80 发表于 2011-6-17 08:00:48 | 显示全部楼层
顶的就是你
authicon 咫尺天 发表于 2011-6-22 11:00:02 | 显示全部楼层
支持!好东西,拿走了!
authicon TRACYFLYING 发表于 2011-6-23 04:00:22 | 显示全部楼层
支持!好东西,拿走了!
authicon lanyuqing 发表于 2011-6-23 05:59:39 | 显示全部楼层
哦哦,发财了啊,看到好东西啦
authicon NicoleOnly 发表于 2011-6-24 09:59:52 | 显示全部楼层
继续来索要
authicon summmer 发表于 2011-8-10 10:31:55 | 显示全部楼层
回贴下载呀
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 14:37

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表