Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9 | daniel-mar | 1 | <?php |
2 | |||
3 | if (isset($argv[1])) { |
||
4 | $ary = explode('&', $argv[1]); |
||
5 | foreach ($ary as $chunk) { |
||
6 | if (trim($chunk) == '') continue; |
||
7 | $param = explode("=", $chunk); |
||
8 | // TODO: also accept parameters without value. as well as arrays... |
||
9 | $_GET[urldecode($param[0])] = urldecode($param[1]); |
||
10 | unset($param); |
||
11 | } |
||
12 | unset($chunk); |
||
13 | unset($ary); |
||
14 | } |
||
15 | |||
16 | if (isset($argv[2])) { |
||
17 | $ary = explode('&', $argv[2]); |
||
18 | foreach ($ary as $chunk) { |
||
19 | if (trim($chunk) == '') continue; |
||
20 | $param = explode("=", $chunk); |
||
21 | $_POST[urldecode($param[0])] = urldecode($param[1]); |
||
22 | unset($param); |
||
23 | } |
||
24 | unset($chunk); |
||
25 | unset($ary); |
||
26 | } |
||
27 | |||
28 | foreach ($_GET as $name => $val) $_REQUEST[$name] = $val; |
||
29 | foreach ($_POST as $name => $val) $_REQUEST[$name] = $val; |
||
30 | unset($name); |
||
31 | unset($val); |
||
32 | |||
33 | // TODO: headers... cookies... decoding of POST (see header)... |
||
34 | $_HEADER = array(); |
||
35 | if (isset($argv[3])) { |
||
36 | $ary = $argv[3]; |
||
37 | $ary = str_replace('|CR|', "\r", $ary); |
||
38 | $ary = str_replace('|LF|', "\n", $ary); |
||
39 | $ary = explode("\r\n", $ary); |
||
40 | foreach ($ary as $chunk) { |
||
41 | if ($chunk == '') continue; |
||
42 | $param = explode(":", $chunk); |
||
43 | $_HEADER[trim($param[0])] = trim($param[1]); // FastPHP specific |
||
44 | // TODO: also generate some usual |
||
45 | |||
46 | // TODO: get more of these: http://php.net/manual/de/reserved.variables.server.php |
||
47 | // TODO: case sensitive? |
||
48 | if (trim($param[0]) == 'User-Agent') $_SERVER['HTTP_USER_AGENT'] = trim($param[1]); |
||
49 | if (trim($param[0]) == 'Referer') $_SERVER['HTTP_REFERER'] = trim($param[1]); |
||
50 | |||
51 | unset($param); |
||
52 | } |
||
53 | unset($chunk); |
||
54 | unset($ary); |
||
55 | } |
||
56 | |||
57 | |||
58 | |||
59 | # --- |
||
60 | |||
61 | // https://gist.github.com/pokeb/10590 |
||
62 | /* |
||
63 | function parse_cookies($header) { |
||
64 | |||
65 | $cookies = array(); |
||
66 | |||
67 | $cookie = new cookie(); |
||
68 | |||
69 | $parts = explode("=",$header); |
||
70 | for ($i=0; $i< count($parts); $i++) { |
||
71 | $part = $parts[$i]; |
||
72 | if ($i==0) { |
||
73 | $key = $part; |
||
74 | continue; |
||
75 | } elseif ($i== count($parts)-1) { |
||
76 | $cookie->set_value($key,$part); |
||
77 | $cookies[] = $cookie; |
||
78 | continue; |
||
79 | } |
||
80 | $comps = explode(" ",$part); |
||
81 | $new_key = $comps[count($comps)-1]; |
||
82 | $value = substr($part,0,strlen($part)-strlen($new_key)-1); |
||
83 | $terminator = substr($value,-1); |
||
84 | $value = substr($value,0,strlen($value)-1); |
||
85 | $cookie->set_value($key,$value); |
||
86 | if ($terminator == ",") { |
||
87 | $cookies[] = $cookie; |
||
88 | $cookie = new cookie(); |
||
89 | } |
||
90 | |||
91 | $key = $new_key; |
||
92 | } |
||
93 | return $cookies; |
||
94 | } |
||
95 | |||
96 | class cookie { |
||
97 | public $name = ""; |
||
98 | public $value = ""; |
||
99 | public $expires = ""; |
||
100 | public $domain = ""; |
||
101 | public $path = ""; |
||
102 | public $secure = false; |
||
103 | |||
104 | public function set_value($key,$value) { |
||
105 | switch (strtolower($key)) { |
||
106 | case "expires": |
||
107 | $this->expires = $value; |
||
108 | return; |
||
109 | case "domain": |
||
110 | $this->domain = $value; |
||
111 | return; |
||
112 | case "path": |
||
113 | $this->path = $value; |
||
114 | return; |
||
115 | case "secure": |
||
116 | $this->secure = ($value == true); |
||
117 | return; |
||
118 | } |
||
119 | if ($this->name == "" && $this->value == "") { |
||
120 | $this->name = $key; |
||
121 | $this->value = $value; |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | */ |