Commit | Line | Data |
---|---|---|
8de51304 H |
1 | <?php\r |
2 | \r | |
3 | // set some variables\r | |
4 | $host = "localhost";\r | |
5 | $port = 81;\r | |
6 | \r | |
7 | $header = \r | |
8 | "HTTP/1.0 200 OK\n".\r | |
9 | "Server: Harvie's HTTPd\n".\r | |
10 | "Connection: close\n\n";\r | |
11 | \r | |
12 | /*\r | |
13 | HTTP/1.0 200 OK\r | |
14 | Date: Thu, 05 Jul 2007 17:28:16 GMT\r | |
15 | Server: Apache/2.0.59 (Win32) PHP/5.1.4\r | |
16 | Content-Length: 5568\r | |
17 | Connection: close\r | |
18 | Content-Type: text/html;charset=utf-8\r | |
19 | */\r | |
20 | \r | |
21 | // don't timeout!\r | |
22 | set_time_limit(0);\r | |
23 | \r | |
24 | while(1) {\r | |
25 | \r | |
26 | $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");\r | |
27 | $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");\r | |
28 | $result = socket_listen($socket, 3) or die("Could not set up socket listener\n");\r | |
29 | \r | |
30 | // accept incoming connections\r | |
31 | // spawn another socket to handle communication\r | |
32 | $spawn = socket_accept($socket) or die("Could not accept incoming connection\n");\r | |
33 | \r | |
34 | $loop = 1;\r | |
35 | while($line = socket_read($spawn, 1024) && $loop) {\r | |
36 | echo($line);\r | |
37 | if(eregi("(GET|POST)", $line)) {\r | |
38 | $line = trim($line);\r | |
39 | echo($line);\r | |
40 | $line = explode(" ", $line);\r | |
41 | readfile(".".$line[1]);\r | |
42 | $loop = 0;\r | |
43 | }\r | |
44 | }\r | |
45 | \r | |
46 | // read client input\r | |
47 | //$input = socket_read($spawn, 1024) or die("Could not read input\n");\r | |
48 | // clean up input string\r | |
49 | //$input = trim($input);\r | |
50 | // reverse client input and send back\r | |
51 | //$output = strrev($input) . "\n";\r | |
52 | //socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");\r | |
53 | \r | |
54 | // close sockets\r | |
55 | socket_close($spawn);\r | |
56 | socket_close($socket);\r | |
57 | \r | |
58 | }\r | |
59 | \r | |
60 | ?>\r | |
61 | \r |