forked from koljenovic/BH-Mobile-SMS-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookiejar.php
49 lines (43 loc) · 1.08 KB
/
cookiejar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class CookieJar
{
protected $cookieJar;
public function __construct($header = null)
{
$this->cookieJar = array();
if($header) {
$this->setCookies($header);
}
return $this;
}
public function setCookies($header)
{
$tmp = array();
preg_match_all('%(?<=Set-Cookie:\s).*?;%im', $header, $tmp);
foreach($tmp[0] as $tmp_cookie) {
$split = explode('=', $tmp_cookie);
$this->cookieJar[$split[0]] = rtrim($split[1], ';');
}
return $this;
}
public function getCookies()
{
return $this->cookieJar;
}
public function getCookie($name)
{
return isset($this->cookieJar[$name]) ? $this->cookieJar[$name] : NULL;
}
public function cookiesToString()
{
if($this->cookieJar) {
$result = '';
foreach($this->cookieJar as $name => $value) {
$result .= $name . '=' . $value . ';';
}
return $result;
} else {
return null;
}
}
}