Skip navigation.

极湖

无不用其“极”

Zend Framework 下实现简单的 proxy 功能

用 Zend_Http_Client 可实现简单的 Proxy 功能,代码如下:
public function proxyAction()
{
    $params = $this->_getAllParams();
    if(!isset($params['url'])) {
        echo 'URL未指定。';
    } else {
        $http = new Zend_Http_Client($params['url']);
        $response = $http->request();
        if ($response->getStatus() == 200) {
            header('Content-Type: text/html; charset=utf-8');
            echo mb_convert_encoding($response->getBody(), "utf-8", "auto");
        } else {
            echo 'HTTP通信错误发生。<br />' . $response->getStatus() . ": " . $response->getMessage();
        }
    }
}

用法:
http://domainname/proxy?url=http://....

用于分割字符串的两个 PHP 函数在虚拟主机上创建 Symbol Link

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31