Added lot of junk laying around on harvie.cz
[mirrors/Programs.git] / php / skripty / http_serv.php
diff --git a/php/skripty/http_serv.php b/php/skripty/http_serv.php
new file mode 100644 (file)
index 0000000..e08813a
--- /dev/null
@@ -0,0 +1,61 @@
+<?php\r
+\r
+// set some variables\r
+$host = "localhost";\r
+$port = 81;\r
+\r
+$header = \r
+  "HTTP/1.0 200 OK\n".\r
+  "Server: Harvie's HTTPd\n".\r
+  "Connection: close\n\n";\r
+\r
+/*\r
+HTTP/1.0 200 OK\r
+Date: Thu, 05 Jul 2007 17:28:16 GMT\r
+Server: Apache/2.0.59 (Win32) PHP/5.1.4\r
+Content-Length: 5568\r
+Connection: close\r
+Content-Type: text/html;charset=utf-8\r
+*/\r
+\r
+// don't timeout!\r
+set_time_limit(0);\r
+\r
+while(1) {\r
+\r
+$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");\r
+$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");\r
+$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");\r
+\r
+// accept incoming connections\r
+// spawn another socket to handle communication\r
+$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");\r
+\r
+$loop = 1;\r
+while($line = socket_read($spawn, 1024) && $loop) {\r
+  echo($line);\r
+  if(eregi("(GET|POST)", $line)) {\r
+    $line = trim($line);\r
+    echo($line);\r
+    $line = explode(" ", $line);\r
+    readfile(".".$line[1]);\r
+    $loop = 0;\r
+  }\r
+}\r
+\r
+// read client input\r
+//$input = socket_read($spawn, 1024) or die("Could not read input\n");\r
+// clean up input string\r
+//$input = trim($input);\r
+// reverse client input and send back\r
+//$output = strrev($input) . "\n";\r
+//socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");\r
+\r
+// close sockets\r
+socket_close($spawn);\r
+socket_close($socket);\r
+\r
+}\r
+\r
+?>\r
+\r
This page took 0.140781 seconds and 4 git commands to generate.