Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function http_parse_headers($headers)
- {
- $return_headers = array();
- foreach (explode("\n", $headers) as $line)
- {
- if (substr($line, 0, 4) == 'HTTP')
- {
- continue;
- }
- $is_cookie = FALSE;
- if (substr($line, 0, 10) == 'Set-Cookie')
- {
- $is_cookie = TRUE;
- }
- $expl = explode(':', $line);
- if (count($expl) == 2)
- {
- if ($is_cookie)
- {
- if (!isset($return_headers[$expl[0]]))
- {
- $return_headers[$expl[0]] = array();
- }
- preg_match_all("/^Set-Cookie: (.*?)=(.*?);/i", $line, $matches);
- if (count($matches) == 3)
- {
- $return_headers[$expl[0]][$matches[1][0]] = trim($matches[2][0]);
- }
- else {
- $return_headers[$expl[0]][] = trim($expl[1]);
- }
- }
- else {
- $return_headers[$expl[0]] = trim($expl[1]);
- }
- }
- }
- return $return_headers;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement