- $finalUrl = $this->url;
- if ( isset( $this->respHeaders['location'] ) ) {
- $redir = $this->respHeaders['location'];
- $finalUrl = $redir[count($redir) - 1];
- }
-
- return $finalUrl;
- }
-}
-
-
-class Cookie {
- protected $name;
- protected $value;
- protected $expires;
- protected $path;
- protected $domain;
- protected $isSessionKey = true;
- // TO IMPLEMENT protected $secure
- // TO IMPLEMENT? protected $maxAge (add onto expires)
- // TO IMPLEMENT? protected $version
- // TO IMPLEMENT? protected $comment
-
- function __construct( $name, $value, $attr ) {
- $this->name = $name;
- $this->set( $value, $attr );
- }
-
- /**
- * Sets a cookie. Used before a request to set up any individual
- * cookies. Used internally after a request to parse the
- * Set-Cookie headers.
- * @param $name string the name of the cookie
- * @param $value string the value of the cookie
- * @param $attr array possible key/values:
- * expires A date string
- * path The path this cookie is used on
- * domain Domain this cookie is used on
- */
- public function set( $value, $attr ) {
- $this->value = $value;
- if( isset( $attr['expires'] ) ) {
- $this->isSessionKey = false;
- $this->expires = strtotime( $attr['expires'] );
- }
- if( isset( $attr['path'] ) ) {
- $this->path = $attr['path'];
- } else {
- $this->path = "/";
- }
- if( isset( $attr['domain'] ) ) {
- $this->domain = $attr['domain'];
- } else {
- throw new MWException("You must specify a domain.");
- }
- }
-
- /**
- * Serialize the cookie jar into a format useful for HTTP Request headers.
- * @param $path string the path that will be used. Required.
- * @param $domain string the domain that will be used. Required.
- * @return string
- */
- public function serializeToHttpRequest( $path, $domain ) {
- $ret = "";
-
- if( $this->canServeDomain( $domain )
- && $this->canServePath( $path )
- && $this->isUnExpired() ) {
- $ret = $this->name ."=". $this->value;
- }
-
- return $ret;
- }
-
- protected function canServeDomain( $domain ) {
- if( $this->domain && substr_compare( $domain, $this->domain, -strlen( $this->domain ),
- strlen( $this->domain ), TRUE ) == 0 ) {
- return true;
- }
- return false;
- }