php使用curl抓取qq空间的访客信息示例(3)

if (is_array($cookies)) {
            foreach ($cookies as $k => $cookie) {
                $line = $cookie['domain'] . "\t" . "TRUE" . "\t" . $cookie['path'] . "\t" . "FALSE" . "\t" . $cookie['expires'] . "\t" . $k . "\t" . $cookie['value'];
                $arr[] = $line;
            }
        }
        return $arr;
    }

protected function __setCookies($cookies)
    {
        $new_line = array();
        if (is_array($cookies)) {
            if ($this->isValidateCookieFile($this->cookie_file)) {
                $content = file($this->cookie_file);
                if (is_array($content)) {
                    foreach ($content as $line) {
                        $line = trim($line);
                        if (strlen($line) > 0 && $line[0] != '#') {
                            $cookie = (preg_split("/\s+/", $line));
                            if (!in_array($cookie[5], $cookies)) {
                                $new_line[] = $line;
                            }
                        } else {
                            $new_line[] = $line;
                        }
                    }
                }
            }

file_put_contents($this->cookie_file, implode("\n", array_merge($new_line, $this->buildCookieStr($cookies))));
        }
    }

protected function __getAllCookies($refresh = false)
    {
        if ($refresh) {
            $this->cookie_list = $this->extractFile();
        }
        return $this->cookie_list;
    }

protected function __getCookie($cookie_name, $refresh = false)
    {
        $cookie_list = $this->__getAllCookies($refresh);

if (is_array($cookie_list) && array_key_exists($cookie_name, $cookie_list)) {
            return $cookie_list[$cookie_name];
        } else {
            return null;
        }
    }

protected function __clearAllCookies()
    {
        $this->cookie_list = null;
        @unlink($this->cookie_file);
    }
}

class BaseRequest extends CookieFileExtract
{

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/6a3b396fe61b016e0da9eb2453f6669b.html