My webhost supports both tags, I usually use <?php but I dunno maybe because I coded that piece of code some time ago I had used <?
I just see the script loading. The script doesn't print anything, just send data through port specidifed.
I have also edited the code so that if a file is requested, it would print the file, if a directory listing it requested it would print the dir list...
However, now it doesn't seem to work. The code runs w/o any errors however I saw a CPU usage of %64 when I checked, and it seemed as though when requesting a file I would either get 'transferring data' in firefox or nothing...
<?
ini_set('display_errors', 'On');
ini_set('error_reporting', E_ALL);
$host = "1.1.1.1";
$port = 60000;
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create
socket\n");
// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to
socket\n");
while(true){
//listen for connection
$result = socket_listen($socket, 1024) or die("Could not set up socket
listener\n");
// accept connections
$spawn = socket_accept($socket) or die("Could not accept incoming
connection\n");
// read input
$input = socket_read($spawn, 1024) or die("Could not read input\n");
$input = trim($input);
preg_match('/GET (.*) HTTP/', $input, $get);
$got = $get[1];
if (strpos($got, '.') == true) {
$fname = str_replace("/", "", $get[1]);
$fpath = $fname;
$fsize = filesize($fpath);
$bufsize = 20000;
socket_write($spawn,"HTTP Status Code: HTTP/1.1 200 OK\r\n\r\n");
if(file_exists($fpath)) {
$buf = readfile($fpath);
socket_write($spawn, $buf);
}
else
{
socket_write($spawn, "HTTP/1.1 404 Not Found\r\n\r\n");
}
socket_close($spawn);
}
else {
$dir = "/home/alperc" . $get[1];
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$type = filetype($dir . $file);
$dir = $dir + "File = $file Type = $type <BR>";
}
closedir($dh);
}
}
socket_write($spawn,"HTTP Status Code: HTTP/1.1 200 OK\r\n\r\n $dir");
}
}
//socket_close($socket);
?>
Yeh see any obvious bugs that maybe I missed? 🙁
Thanks...