"Fossies" - the Fresh Open Source Software Archive

Member "libs/PHPCrawler/PHPCrawlerCookieDescriptor.class.php" (8 Jan 2013, 4248 Bytes) of package /linux/www/SitemapCreator.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * Describes a cookie within the PHPCrawl-system.
    4  *
    5  * @package phpcrawl
    6  */ 
    7 class PHPCrawlerCookieDescriptor
    8 {
    9   /**
   10    * Cookie-name
   11    *
   12    * @var string
   13    */
   14   public $name;
   15   
   16   /**
   17    * Cookie-value
   18    *
   19    * @var string
   20    */
   21   public $value;
   22   
   23   /**
   24    * Expire-string, e.g. "Sat, 08-Aug-2020 23:59:08 GMT"
   25    *
   26    * @var string
   27    */
   28   public $expires = null;
   29   
   30   /**
   31    * Expire-date as unix-timestamp
   32    *
   33    * @var int
   34    */
   35   public $expire_timestamp = null;
   36   
   37   /**
   38    * Cookie-path
   39    *
   40    * @var string
   41    */
   42   public $path = null;
   43   
   44   /**
   45    * Cookie-domain
   46    *
   47    * @var string
   48    */
   49   public $domain = null;
   50   
   51   /**
   52    * The domain the cookie was send from
   53    *
   54    * @var string
   55    */
   56   public $source_domain = null;
   57   
   58   /**
   59    * The URL the cookie was send from
   60    *
   61    * @var string
   62    */
   63   public $source_url = null;
   64   
   65   /**
   66    * The time the cookie was send
   67    *
   68    * @var float time in secs and microseconds
   69    */
   70   public $cookie_send_time = null;
   71   
   72   /**
   73    * Initiates a new PHPCrawlerCookieDescriptor-object.
   74    *
   75    * @param string $source_url URL the cookie was send from.
   76    * @param string $name       Cookie-name
   77    * @param string $value      Cookie-value
   78    * @param string $expires    Expire-string, e.g. "Sat, 08-Aug-2020 23:59:08 GMT"
   79    * @param string $path       Cookie-path
   80    * @param string $domain     Cookie-domain
   81    * @internal
   82    */
   83   public function __construct($source_url, $name, $value, $expires = null, $path = null, $domain = null)
   84   {
   85     // For cookie-specs, see e.g. http://curl.haxx.se/rfc/cookie_spec.html
   86     
   87     $this->name = $name;
   88     $this->value = $value;
   89     $this->expires = $expires;
   90     $this->path = $path;
   91     $this->domain = $domain;
   92     
   93     $source_url_parts = PHPCrawlerUtils::splitURL($source_url);
   94     
   95     // Source-domain
   96     $this->source_domain = $source_url_parts["domain"];
   97     
   98     // Source-URL
   99     $this->source_url = $source_url;
  100     
  101     // Send-time
  102     $this->cookie_send_time = PHPCrawlerBenchmark::getmicrotime();
  103       
  104     // Expire-date to timetsamp
  105     if ($this->expires != null)
  106       $this->expire_timestamp = @strtotime($this->expires);
  107     
  108     // If domain doesn't start with "." -> add it (see RFC)
  109     if ($this->domain != null && substr($this->domain, 0, 1) != ".") $this->domain = ".".$this->domain;
  110     
  111     // Comeplete missing values
  112     
  113     // If domain no set -> domain is the host of the source-url WITHOUT leading "."! (see RFC)
  114     if ($this->domain == null) $this->domain = $source_url_parts["host"];
  115 
  116     // If path not set
  117     if ($this->path == null) $this->path = $source_url_parts["path"];
  118   }
  119   
  120   /**
  121    * Returns a PHPCrawlerCookieDescriptor-object initiated by the given cookie-header-line.
  122    *
  123    * @param string $header_line The line from an header defining the cookie, e.g. "VISITOR=4c63394c2d82e31552001a58; expires="Sat, 08-Aug-2020 23:59:08 GMT"; Path=/"
  124    * @param string $source_url  URL the cookie was send from.
  125    * @return PHPCrawlerCookieDescriptor The appropriate PHPCrawlerCookieDescriptor-object.
  126    * @internal
  127    */
  128   public static function getFromHeaderLine($header_line, $source_url)
  129   {
  130     $parts = explode(";", trim($header_line));
  131     
  132     $name = "";
  133     $value = "";
  134     $expires = null;
  135     $path = null;
  136     $domain = "";
  137     
  138     // Name and value
  139     preg_match("#([^=]*)=(.*)#", $parts[0], $match);
  140     $name = trim($match[1]);
  141     $value = trim($match[2]);
  142     
  143     // Path and Expires
  144     for ($x=1; $x<count($parts); $x++)
  145     {
  146       $parts[$x] = trim($parts[$x]);
  147       
  148       if (preg_match("#^expires\s*=(.*)# i", $parts[$x], $match)) $expires = trim($match[1]);
  149       if (preg_match("#^path\s*=(.*)# i", $parts[$x], $match)) $path = trim($match[1]);
  150       if (preg_match("#^domain\s*=(.*)# i", $parts[$x], $match)) $domain = trim($match[1]);
  151     }
  152     
  153     $expires = str_replace("\"", "", $expires);
  154     $path = str_replace("\"", "", $path);
  155     $domain = str_replace("\"", "", $domain);
  156     
  157     return new PHPCrawlerCookieDescriptor($source_url, $name, $value, $expires, $path, $domain);
  158   }
  159 }
  160 ?>