absoluteUrl() public static méthode

Returns an absolute URL for the given one
public static absoluteUrl ( string $url ) : string
$url string absilute or relative URL
Résultat string
 /**
  * Performs check of OpenID identity.
  *
  * This is the first step of OpenID authentication process.
  * On success the function does not return (it does HTTP redirection to
  * server and exits). On failure it returns false.
  *
  * @param bool $immediate enables or disables interaction with user
  * @param string $id OpenID identity
  * @param string $returnTo HTTP URL to redirect response from server to
  * @param string $root HTTP URL to identify consumer on server
  * @param mixed $extensions extension object or array of extensions objects
  * @param Zend_Controller_Response_Abstract $response an optional response
  *  object to perform HTTP or HTML form redirection
  * @return bool
  */
 protected function _checkId($immediate, $id, $returnTo = null, $root = null, $extensions = null, Zend_Controller_Response_Abstract $response = null)
 {
     $this->_setError('');
     if (!Zend_OpenId::normalize($id)) {
         $this->_setError("Normalisation failed");
         return false;
     }
     $claimedId = $id;
     if (!$this->_discovery($id, $server, $version)) {
         $this->_setError("Discovery failed: " . $this->getError());
         return false;
     }
     if (!$this->_associate($server, $version)) {
         $this->_setError("Association failed: " . $this->getError());
         return false;
     }
     if (!$this->_getAssociation($server, $handle, $macFunc, $secret, $expires)) {
         /* Use dumb mode */
         unset($handle);
         unset($macFunc);
         unset($secret);
         unset($expires);
     }
     $params = array();
     if ($version >= 2.0) {
         $params['openid.ns'] = Zend_OpenId::NS_2_0;
     }
     $params['openid.mode'] = $immediate ? 'checkid_immediate' : 'checkid_setup';
     $params['openid.identity'] = $id;
     $params['openid.claimed_id'] = $claimedId;
     if ($version <= 2.0) {
         if ($this->_session !== null) {
             $this->_session->identity = $id;
             $this->_session->claimed_id = $claimedId;
         } else {
             if (defined('SID')) {
                 $_SESSION["zend_openid"] = array("identity" => $id, "claimed_id" => $claimedId);
             } else {
                 require_once "Zend/Session/Namespace.php";
                 $this->_session = new Zend_Session_Namespace("zend_openid");
                 $this->_session->identity = $id;
                 $this->_session->claimed_id = $claimedId;
             }
         }
     }
     if (isset($handle)) {
         $params['openid.assoc_handle'] = $handle;
     }
     $params['openid.return_to'] = Zend_OpenId::absoluteUrl($returnTo);
     if (empty($root)) {
         $root = Zend_OpenId::selfUrl();
         if ($root[strlen($root) - 1] != '/') {
             $root = dirname($root);
         }
     }
     if ($version >= 2.0) {
         $params['openid.realm'] = $root;
     } else {
         $params['openid.trust_root'] = $root;
     }
     if (!Zend_OpenId_Extension::forAll($extensions, 'prepareRequest', $params)) {
         $this->_setError("Extension::prepareRequest failure");
         return false;
     }
     Zend_OpenId::redirect($server, $params, $response);
     return true;
 }
Exemple #2
0
 /**
  * Performs a HTTP redirection to specified URL with additional data.
  * It may generate redirected request using GET or POST HTTP method.
  * The function never returns.
  *
  * @param string $url URL to redirect to
  * @param array $params additional variable/value pairs to send
  * @param Zend_Controller_Response_Abstract $response
  * @param string $method redirection method ('GET' or 'POST')
  */
 public static function redirect($url, $params = null, Zend_Controller_Response_Abstract $response = null, $method = 'GET')
 {
     $url = Zend_OpenId::absoluteUrl($url);
     $body = "";
     if (null === $response) {
         #require_once "Zend/Controller/Response/Http.php";
         $response = new Zend_Controller_Response_Http();
     }
     if ($method == 'POST') {
         $body = "<html><body onLoad=\"document.forms[0].submit();\">\n";
         $body .= "<form method=\"POST\" action=\"{$url}\">\n";
         if (is_array($params) && count($params) > 0) {
             foreach ($params as $key => $value) {
                 $body .= '<input type="hidden" name="' . $key . '" value="' . $value . "\">\n";
             }
         }
         $body .= "<input type=\"submit\" value=\"Continue OpenID transaction\">\n";
         $body .= "</form></body></html>\n";
     } else {
         if (is_array($params) && count($params) > 0) {
             if (strpos($url, '?') === false) {
                 $url .= '?' . self::paramsToQuery($params);
             } else {
                 $url .= '&' . self::paramsToQuery($params);
             }
         }
     }
     if (!empty($body)) {
         $response->setBody($body);
     } else {
         if (!$response->canSendHeaders()) {
             $response->setBody("<script language=\"JavaScript\"" . " type=\"text/javascript\">window.location='{$url}';" . "</script>");
         } else {
             $response->setRedirect($url);
         }
     }
     $response->sendResponse();
     if (self::$exitOnRedirect) {
         exit;
     }
 }
 /**
  * Constructs a Zend_OpenId_Provider object with given parameters.
  *
  * @param string $loginUrl is an URL that provides login screen for
  *  end-user (by default it is the same URL with additional GET variable
  *  openid.action=login)
  * @param string $trustUrl is an URL that shows a question if end-user
  *  trust to given consumer (by default it is the same URL with additional
  *  GET variable openid.action=trust)
  * @param Zend_OpenId_Provider_User $user is an object for communication
  *  with User-Agent and store information about logged-in user (it is a
  *  Zend_OpenId_Provider_User_Session object by default)
  * @param Zend_OpenId_Provider_Storage $storage is an object for keeping
  *  persistent database (it is a Zend_OpenId_Provider_Storage_File object
  *  by default)
  * @param integer $sessionTtl is a default time to live for association
  *   session in seconds (1 hour by default). Consumer must reestablish
  *   association after that time.
  */
 public function __construct($loginUrl = null, $trustUrl = null, Zend_OpenId_Provider_User $user = null, Zend_OpenId_Provider_Storage $storage = null, $sessionTtl = 3600)
 {
     if ($loginUrl === null) {
         $loginUrl = Zend_OpenId::selfUrl() . '?openid.action=login';
     } else {
         $loginUrl = Zend_OpenId::absoluteUrl($loginUrl);
     }
     $this->_loginUrl = $loginUrl;
     if ($trustUrl === null) {
         $trustUrl = Zend_OpenId::selfUrl() . '?openid.action=trust';
     } else {
         $trustUrl = Zend_OpenId::absoluteUrl($trustUrl);
     }
     $this->_trustUrl = $trustUrl;
     if ($user === null) {
         #require_once "Zend/OpenId/Provider/User/Session.php";
         $this->_user = new Zend_OpenId_Provider_User_Session();
     } else {
         $this->_user = $user;
     }
     if ($storage === null) {
         #require_once "Zend/OpenId/Provider/Storage/File.php";
         $this->_storage = new Zend_OpenId_Provider_Storage_File();
     } else {
         $this->_storage = $storage;
     }
     $this->_sessionTtl = $sessionTtl;
 }
    /**
     * testing testAbsolutefUrl
     *
     */
    public function testAbsoluteUrl()
    {
        unset($_SERVER['SCRIPT_URI']);
        unset($_SERVER['HTTPS']);
        unset($_SERVER['HTTP_HOST']);
        unset($_SERVER['SERVER_NAME']);
        unset($_SERVER['SERVER_PORT']);
        unset($_SERVER['SCRIPT_URL']);
        unset($_SERVER['REDIRECT_URL']);
        unset($_SERVER['PHP_SELF']);
        unset($_SERVER['SCRIPT_NAME']);
        unset($_SERVER['PATH_INFO']);

        $_SERVER['HTTP_HOST'] = "www.test.com";
        $_SERVER['SCRIPT_NAME'] = '/a/b/c/test.php';

        $this->assertSame( 'http://www.test.com/a/b/c/test.php', Zend_OpenId::absoluteUrl("") );

        $this->assertSame( 'http://www.test.com/a/b/c/ok.php', Zend_OpenId::absoluteUrl("ok.php") );

        $this->assertSame( 'http://www.test.com/a/ok.php', Zend_OpenId::absoluteUrl("/a/ok.php") );

        $this->assertSame( 'http://www.php.net/ok.php', Zend_OpenId::absoluteUrl("http://www.php.net/ok.php") );

        $this->assertSame( 'https://www.php.net/ok.php', Zend_OpenId::absoluteUrl("https://www.php.net/ok.php") );

        $_SERVER['SCRIPT_NAME'] = '/test.php';
        $this->assertSame( 'http://www.test.com/a/b.php', Zend_OpenId::absoluteUrl("/a/b.php") );

        $this->assertSame( 'http://www.test.com/a/b.php', Zend_OpenId::absoluteUrl("a/b.php") );
    }
Exemple #5
0
 /**
  * Performs check of OpenID identity.
  *
  * This is the first step of OpenID authentication process.
  * On success the function does not return (it does HTTP redirection to
  * server and exits). On failure it returns false.
  *
  * @param bool $immediate enables or disables interaction with user
  * @param string $id OpenID identity
  * @param string $returnTo HTTP URL to redirect response from server to
  * @param string $root HTTP URL to identify consumer on server
  * @param mixed $extensions extension object or array of extensions objects
  * @param Zend_Controller_Response_Abstract $response an optional response
  *  object to perform HTTP or HTML form redirection
  * @return bool
  */
 protected function _checkId($immediate, $id, $returnTo = null, $root = null, $extensions = null, Zend_Controller_Response_Abstract $response = null)
 {
     if (!Zend_OpenId::normalize($id)) {
         return false;
     }
     $claimedId = $id;
     if (!$this->_discovery($id, $server, $version)) {
         return false;
     }
     if (!$this->_associate($server, $version)) {
         return false;
     }
     if (!$this->_getAssociation($server, $handle, $macFunc, $secret, $expires)) {
         /* Use dumb mode */
         unset($handle);
         unset($macFunc);
         unset($secret);
         unset($expires);
     }
     $params = array();
     if ($version >= 2.0) {
         $params['openid.ns'] = Zend_OpenId::NS_2_0;
     }
     $params['openid.mode'] = $immediate ? 'checkid_immediate' : 'checkid_setup';
     $params['openid.identity'] = $id;
     $params['openid.claimed_id'] = $claimedId;
     if (isset($handle)) {
         $params['openid.assoc_handle'] = $handle;
     }
     $params['openid.return_to'] = Zend_OpenId::absoluteUrl($returnTo);
     if (empty($root)) {
         $root = dirname(Zend_OpenId::selfUrl());
     }
     if ($version >= 2.0) {
         $params['openid.realm'] = $root;
     } else {
         $params['openid.trust_root'] = $root;
     }
     if (!Zend_OpenId_Extension::forAll($extensions, 'prepareRequest', $params)) {
         return false;
     }
     Zend_OpenId::redirect($server, $params, $response);
     return true;
 }
 /**
  * Performs check of OpenID identity.
  *
  * This is the first step of OpenID authentication process.
  * On success the function does not return (it does HTTP redirection to
  * server and exits). On failure it returns false.
  *
  * @param bool $immediate enables or disables interaction with user
  * @param string $id OpenID identity
  * @param string $returnTo HTTP URL to redirect response from server to
  * @param string $root HTTP URL to identify consumer on server
  * @param mixed $extensions extension object or array of extensions objects
  * @param Zend_Controller_Response_Abstract $response an optional response
  *  object to perform HTTP or HTML form redirection
  * @return bool
  */
 protected function _checkId($immediate, $id, $returnTo = null, $root = null, $extensions = null, Zend_Controller_Response_Abstract $response = null)
 {
     $this->_setError('');
     if (!Zend_OpenId::normalize($id)) {
         $this->_setError("Normalisation failed");
         return false;
     }
     $claimedId = $id;
     if (!$this->_discovery($id, $server, $version)) {
         $this->_setError("Discovery failed: " . $this->getError());
         return false;
     }
     if (!$this->_associate($server, $version)) {
         $this->_setError("Association failed: " . $this->getError());
         return false;
     }
     if (!$this->_getAssociation($server, $handle, $macFunc, $secret, $expires)) {
         /* Use dumb mode */
         unset($handle);
         unset($macFunc);
         unset($secret);
         unset($expires);
     }
     $params = array();
     if ($version >= 2.0) {
         $params['openid.ns'] = Zend_OpenId::NS_2_0;
     }
     $params['openid.mode'] = $immediate ? 'checkid_immediate' : 'checkid_setup';
     $params['openid.identity'] = $id;
     $params['openid.claimed_id'] = $claimedId;
     if ($version <= 2.0) {
         if ($this->_session !== null) {
             $this->_session->identity = $id;
             $this->_session->claimed_id = $claimedId;
             if ($server == 'https://www.google.com/accounts/o8/ud') {
                 $params['openid.identity'] = 'http://specs.openid.net/auth/2.0/identifier_select';
                 $params['openid.claimed_id'] = 'http://specs.openid.net/auth/2.0/identifier_select';
                 $params['openid.ns.ax'] = 'http://openid.net/srv/ax/1.0';
                 $params['openid.ax.mode'] = 'fetch_request';
                 $params['openid.ax.type.email'] = 'http://axschema.org/contact/email';
                 $params['openid.ax.type.country'] = 'http://axschema.org/contact/country/home';
                 $params['openid.ax.type.firstname'] = 'http://axschema.org/namePerson/first';
                 $params['openid.ax.type.lastname'] = 'http://axschema.org/namePerson/last';
                 $params['openid.ax.type.language'] = 'http://axschema.org/pref/language';
                 $params['openid.ax.required'] = 'country,firstname,email,language,lastname';
             }
         } else {
             if (defined('SID')) {
                 $_SESSION["zend_openid"] = array("identity" => $id, "claimed_id" => $claimedId);
             } else {
                 require_once "Zend/Session/Namespace.php";
                 $this->_session = new Zend_Session_Namespace("zend_openid");
                 $this->_session->identity = $id;
                 $this->_session->claimed_id = $claimedId;
             }
         }
     }
     if (isset($handle)) {
         $params['openid.assoc_handle'] = $handle;
     }
     $params['openid.return_to'] = Zend_OpenId::absoluteUrl($returnTo);
     if (empty($root)) {
         $root = Zend_OpenId::selfUrl();
         if ($root[strlen($root) - 1] != '/') {
             $root = dirname($root);
         }
     }
     if ($version >= 2.0) {
         $params['openid.realm'] = $root;
     } else {
         $params['openid.trust_root'] = $root;
     }
     if (!Zend_OpenId_Extension::forAll($extensions, 'prepareRequest', $params)) {
         $this->_setError("Extension::prepareRequest failure");
         return false;
     }
     Zend_OpenId::redirect($server, $params, $response);
     return true;
 }