-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfastphp_server.inc.php
125 lines (109 loc) · 2.91 KB
/
fastphp_server.inc.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
if (isset($argv[1])) {
$ary = explode('&', $argv[1]);
foreach ($ary as $chunk) {
if (trim($chunk) == '') continue;
$param = explode("=", $chunk);
// TODO: also accept parameters without value. as well as arrays...
$_GET[urldecode($param[0])] = urldecode($param[1]);
unset($param);
}
unset($chunk);
unset($ary);
}
if (isset($argv[2])) {
$ary = explode('&', $argv[2]);
foreach ($ary as $chunk) {
if (trim($chunk) == '') continue;
$param = explode("=", $chunk);
$_POST[urldecode($param[0])] = urldecode($param[1]);
unset($param);
}
unset($chunk);
unset($ary);
}
foreach ($_GET as $name => $val) $_REQUEST[$name] = $val;
foreach ($_POST as $name => $val) $_REQUEST[$name] = $val;
unset($name);
unset($val);
// TODO: headers... cookies... decoding of POST (see header)...
$_HEADER = array();
if (isset($argv[3])) {
$ary = $argv[3];
$ary = str_replace('|CR|', "\r", $ary);
$ary = str_replace('|LF|', "\n", $ary);
$ary = explode("\r\n", $ary);
foreach ($ary as $chunk) {
if ($chunk == '') continue;
$param = explode(":", $chunk);
$_HEADER[trim($param[0])] = trim($param[1]); // FastPHP specific
// TODO: also generate some usual
// TODO: get more of these: http://php.net/manual/de/reserved.variables.server.php
// TODO: case sensitive?
if (trim($param[0]) == 'User-Agent') $_SERVER['HTTP_USER_AGENT'] = trim($param[1]);
if (trim($param[0]) == 'Referer') $_SERVER['HTTP_REFERER'] = trim($param[1]);
unset($param);
}
unset($chunk);
unset($ary);
}
# ---
// https://gist.github.com/pokeb/10590
/*
function parse_cookies($header) {
$cookies = array();
$cookie = new cookie();
$parts = explode("=",$header);
for ($i=0; $i< count($parts); $i++) {
$part = $parts[$i];
if ($i==0) {
$key = $part;
continue;
} elseif ($i== count($parts)-1) {
$cookie->set_value($key,$part);
$cookies[] = $cookie;
continue;
}
$comps = explode(" ",$part);
$new_key = $comps[count($comps)-1];
$value = substr($part,0,strlen($part)-strlen($new_key)-1);
$terminator = substr($value,-1);
$value = substr($value,0,strlen($value)-1);
$cookie->set_value($key,$value);
if ($terminator == ",") {
$cookies[] = $cookie;
$cookie = new cookie();
}
$key = $new_key;
}
return $cookies;
}
class cookie {
public $name = "";
public $value = "";
public $expires = "";
public $domain = "";
public $path = "";
public $secure = false;
public function set_value($key,$value) {
switch (strtolower($key)) {
case "expires":
$this->expires = $value;
return;
case "domain":
$this->domain = $value;
return;
case "path":
$this->path = $value;
return;
case "secure":
$this->secure = ($value == true);
return;
}
if ($this->name == "" && $this->value == "") {
$this->name = $key;
$this->value = $value;
}
}
}
*/