⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openid.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category   Zend * @package    Zend_OpenId * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License * @version    $Id: OpenId.php 8243 2008-02-21 12:39:56Z dmitry $ *//** * @see Zend_OpenId_Exception */require_once "Zend/OpenId/Exception.php";/** * @see Zend_Controller_Response_Abstract */require_once "Zend/Controller/Response/Abstract.php";/** * Static class that contains common utility functions for * {@link Zend_OpenId_Consumer} and {@link Zend_OpenId_Provider}. * * This class implements common utility functions that are used by both * Consumer and Provider. They include functions for Diffie-Hellman keys * generation and exchange, URL normalization, HTTP redirection and some others. * * @category   Zend * @package    Zend_OpenId * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License */class Zend_OpenId{    /**     * Default Diffie-Hellman key generator (1024 bit)     */    const DH_P   = 'dcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61ef75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d2683705577d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e3826634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22c583ab';    /**     * Default Diffie-Hellman prime number (should be 2 or 5)     */    const DH_G   = '02';    /**     * OpenID 2.0 namespace. All OpenID 2.0 messages MUST contain variable     * openid.ns with its value.     */    const NS_2_0 = 'http://specs.openid.net/auth/2.0';    /**     * Allows enable/disable stoping execution of PHP script after redirect()     */    static public $exitOnRedirect = true;    /**     * Returns a full URL that was requested on current HTTP request.     *     * @return string     */    static public function selfUrl()    {        if (isset($_SERVER['SCRIPT_URI'])) {            return $_SERVER['SCRIPT_URI'];        }        $url = '';        $port = '';        if (isset($_SERVER['HTTP_HOST'])) {            if (($pos = strpos($_SERVER['HTTP_HOST'], ':')) === false) {                if (isset($_SERVER['SERVER_PORT'])) {                    $port = ':' . $_SERVER['SERVER_PORT'];                }                $url = $_SERVER['HTTP_HOST'];            } else {                $url = substr($_SERVER['HTTP_HOST'], 0, $pos);                $port = substr($_SERVER['HTTP_HOST'], $pos);            }        } else if (isset($_SERVER['SERVER_NAME'])) {            $url = $_SERVER['SERVER_NAME'];            if (isset($_SERVER['SERVER_PORT'])) {                $port = ':' . $_SERVER['SERVER_PORT'];            }        }        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {            $url = 'https://' . $url;            if ($port == ':443') {                $port = '';            }        } else {            $url = 'http://' . $url;            if ($port == ':80') {                $port = '';            }        }        $url .= $port;        if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {            $url .= $_SERVER['HTTP_X_REWRITE_URL'];        } elseif (isset($_SERVER['REQUEST_URI'])) {            $query = strpos($_SERVER['REQUEST_URI'], '?');            if ($query === false) {                $url .= $_SERVER['REQUEST_URI'];            } else {                $url .= substr($_SERVER['REQUEST_URI'], 0, $query);            }        } else if (isset($_SERVER['SCRIPT_URL'])) {            $url .= $_SERVER['SCRIPT_URL'];        } else if (isset($_SERVER['REDIRECT_URL'])) {            $url .= $_SERVER['REDIRECT_URL'];        } else if (isset($_SERVER['PHP_SELF'])) {            $url .= $_SERVER['PHP_SELF'];        } else if (isset($_SERVER['SCRIPT_NAME'])) {            $url .= $_SERVER['SCRIPT_NAME'];            if (isset($_SERVER['PATH_INFO'])) {                $url .= $_SERVER['PATH_INFO'];            }        }        return $url;    }    /**     * Returns an absolute URL for the given one     *     * @param string $url absilute or relative URL     * @return string     */    static public function absoluteUrl($url)    {        if (empty($url)) {            return Zend_OpenId::selfUrl();        } else if (!preg_match('|^([^:]+)://|', $url)) {            if (preg_match('|^([^:]+)://([^:@]*(?:[:][^@]*)?@)?([^/:@?#]*)(?:[:]([^/?#]*))?(/[^?]*)?((?:[?](?:[^#]*))?(?:#.*)?)$|', Zend_OpenId::selfUrl(), $reg)) {                $scheme = $reg[1];                $auth = $reg[2];                $host = $reg[3];                $port = $reg[4];                $path = $reg[5];                $query = $reg[6];                if ($url[0] == '/') {                    return $scheme                        . '://'                        . $auth                        . $host                        . (empty($port) ? '' : (':' . $port))                        . $url;                } else {                    $dir = dirname($path);                    return $scheme                        . '://'                        . $auth                        . $host                        . (empty($port) ? '' : (':' . $port))                        . (strlen($dir) > 1 ? $dir : '')                        . '/'                        . $url;                }            }        }        return $url;    }    /**     * Converts variable/value pairs into URL encoded query string     *     * @param array $params variable/value pairs     * @return string URL encoded query string     */    static public function paramsToQuery($params)    {        foreach($params as $key => $value) {            if (isset($query)) {                $query .= '&' . $key . '=' . urlencode($value);            } else {                $query = $key . '=' . urlencode($value);            }        }        return isset($query) ? $query : '';    }    /**     * Normalizes URL according to RFC 3986 to use it in comparison operations.     * The function gets URL argument by reference and modifies it.     * It returns true on success and false of failure.     *     * @param string &$id url to be normalized     * @return bool     */    static public function normalizeUrl(&$id)    {        // RFC 3986, 6.2.2.  Syntax-Based Normalization        // RFC 3986, 6.2.2.2 Percent-Encoding Normalization        $i = 0;        $n = strlen($id);        $res = '';        while ($i < $n) {            if ($id[$i] == '%') {                if ($i + 2 >= $n) {                    return false;                }                ++$i;                if ($id[$i] >= '0' && $id[$i] <= '9') {                    $c = ord($id[$i]) - ord('0');                } else if ($id[$i] >= 'A' && $id[$i] <= 'F') {                    $c = ord($id[$i]) - ord('A') + 10;                } else if ($id[$i] >= 'a' && $id[$i] <= 'f') {                    $c = ord($id[$i]) - ord('a') + 10;                } else {                    return false;                }                ++$i;                if ($id[$i] >= '0' && $id[$i] <= '9') {                    $c = ($c << 4) | (ord($id[$i]) - ord('0'));                } else if ($id[$i] >= 'A' && $id[$i] <= 'F') {                    $c = ($c << 4) | (ord($id[$i]) - ord('A') + 10);                } else if ($id[$i] >= 'a' && $id[$i] <= 'f') {                    $c = ($c << 4) | (ord($id[$i]) - ord('a') + 10);                } else {                    return false;                }                ++$i;                $ch = chr($c);                if (($ch >= 'A' && $ch <= 'Z') ||                    ($ch >= 'a' && $ch <= 'z') ||                    $ch == '-' ||                    $ch == '.' ||                    $ch == '_' ||                    $ch == '~') {                    $res .= $ch;                } else {                    $res .= '%';                    if (($c >> 4) < 10) {                        $res .= chr(($c >> 4) + ord('0'));                    } else {                        $res .= chr(($c >> 4) - 10 + ord('A'));                    }                    $c = $c & 0xf;                    if ($c < 10) {                        $res .= chr($c + ord('0'));                    } else {                        $res .= chr($c - 10 + ord('A'));                    }                }            } else {                $res .= $id[$i++];            }        }        if (!preg_match('|^([^:]+)://([^:@]*(?:[:][^@]*)?@)?([^/:@?#]*)(?:[:]([^/?#]*))?(/[^?]*)?((?:[?](?:[^#]*))?(?:#.*)?)$|', $res, $reg)) {            return false;        }        $scheme = $reg[1];        $auth = $reg[2];        $host = $reg[3];        $port = $reg[4];        $path = $reg[5];        $query = $reg[6];        if (empty($scheme) || empty($host)) {            return false;        }        // RFC 3986, 6.2.2.1.  Case Normalization        $scheme = strtolower($scheme);        $host = strtolower($host);        // RFC 3986, 6.2.2.3.  Path Segment Normalization        if (!empty($path)) {            $i = 0;            $n = strlen($path);            $res = "";            while ($i < $n) {                if ($path[$i] == '/') {                    ++$i;                    while ($i < $n && $path[$i] == '/') {                        ++$i;                    }                    if ($i < $n && $path[$i] == '.') {                        ++$i;                        if ($i < $n && $path[$i] == '.') {                            ++$i;                            if ($i == $n || $path[$i] == '/') {                                if (($pos = strrpos($res, '/')) !== false) {                                    $res = substr($res, 0, $pos);                                }                            } else {                                    $res .= '/..';                            }                        } else if ($i != $n && $path[$i] != '/') {                            $res .= '/.';                        }                    } else {                        $res .= '/';                    }                } else {                    $res .= $path[$i++];                }            }            $path = $res;        }        // RFC 3986,6.2.3.  Scheme-Based Normalization        if ($scheme == 'http') {            if ($port == 80) {                $port = '';            }        } else if ($scheme == 'https') {            if ($port == 443) {                $port = '';            }        }        if (empty($path)) {            $path = '/';        }        $id = $scheme            . '://'            . $auth            . $host            . (empty($port) ? '' : (':' . $port))            . $path            . $query;        return true;    }    /**     * Normalizes OpenID identifier that can be URL or XRI name.     * Returns true on success and false of failure.     *     * Normalization is performed according to the following rules:     * 1. If the user's input starts with one of the "xri://", "xri://$ip*",     *    or "xri://$dns*" prefixes, they MUST be stripped off, so that XRIs     *    are used in the canonical form, and URI-authority XRIs are further     *    considered URL identifiers.     * 2. If the first character of the resulting string is an XRI Global     *    Context Symbol ("=", "@", "+", "$", "!"), then the input SHOULD be     *    treated as an XRI.     * 3. Otherwise, the input SHOULD be treated as an http URL; if it does     *    not include a "http" or "https" scheme, the Identifier MUST be     *    prefixed with the string "http://".     * 4. URL identifiers MUST then be further normalized by both following

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -