This is a Web Server entierly written in PHP. PHP 4.2.2 is needed with Sockets included in the ini file...I had a problem with images and zips but its fixed now.
By : micah
<?php
//MicahServer v. 3.2PHP
//By Micah Lansing - sw_freak@hotmail.com
//www.ForeverCode.d2g.com
//August 1st 2002
echo "<html><head><title>Micah's PHP Web server!</title></head><body>";
set_time_limit (0); //Timout, keep at 0
ob_implicit_flush (); //Output data to the web brouser or console as we go
$address = '192.168.1.3'; //your ip
$port = 80; //Port to listen
$sock = socket_create (AF_INET, SOCK_STREAM, 0) or die ("socket_create() failed.");
@socket_bind ($sock, $address, $port) or die ("socket_bind() failed");
@socket_listen ($sock, 5) or die("socket_listen() failed");
echo "<font color = 'red'>Server Started.<br><br></font>";
do {
if (($Thesocket = socket_accept($sock)) < 0) {
echo "socket_accept() failed: reason: " . socket_strerror ($msgsock) . "\n";
break;
}
if (FALSE === ($buf = socket_read ($Thesocket, 2048))) {
echo "socket_read() failed: reason: " . socket_strerror ($ret) . "\n";
break 2;
}
$some = substr ( $buf, 4, strlen($buf));
$rest = strstr ( $some, " ");
$request = substr ( $some, 0 , strlen($some) - strlen($rest));
if($request == "/Down") die ("<br><br><font color = 'red'>Server Shut Down.</font>");
if($request == "/"){
$request = "\index.html";
$mime = "text/html";
} else {
$rev = strrev($request);
$dot = strstr ( $rev, ".");
$GetEX = substr ( $request, strlen($dot), strlen($request) - strlen($dot));
switch ( $GetEX ) {
case $GetEX == "gif":
$mime = "image/gif";
break;
case $GetEX == "jpg":
$mime = "image/jpeg";
break;
case $GetEX == "zip":
$mime = "aplication/zip";
break;
case $GetEX == "exe":
$mime = "aplication/exe";
break;
case $GetEX == "bmp":
$mime = "image/bmp";
break;
case $GetEX == "mov":
$mime = "video/quicktime";
break;
case $GetEX == "mp3":
$mime = "video/mpeg";
break;
case $GetEX == "mpeg":
$mime = "video/mpeg";
break;
case $GetEX == "txt":
$mime = "text/plain";
break;
default:
$mime = "text/html";
break;
}
}
$request = ereg_replace ( "/", "//", $request);
$content = "";
$filename = "C:\html\phpserver" .$request;
$fd = @fopen ($filename, "rb");
if ($fd){
$content = fread ($fd, filesize ($filename));
fclose ($fd);
}
if( $content == "" ){
$lens = strlen($content);
$datas = "HTTP/1.0 404 OBJECT NOT FOUND\r\nServer: MicahServer 3.2PHP\r\nDate: 8/01/02\r\nConnection: close\r\nContent-Length: $lens\r\nContent-Type: text/html\r\n\r\n$content";
socket_write ($Thesocket, $datas, strlen ($datas));
} else {
$lens = filesize ($filename);
$today = date("m.d.y");
$datas = "HTTP/1.0 200 OK\r\nServer: MicahServer 3.2PHP\r\nDate: $today\r\nConnection: close\r\nContent-Length: $lens\r\nContent-Type: $mime\r\n\r\n";
socket_send ($Thesocket, $datas, strlen ($datas), 0);
$S = 0;
$copyD = "";
$DD = filesize ($filename);
while($S <= $DD){
$TempD = substr( $content, $S, 2048);
$S += 2048;
socket_write ($Thesocket, $TempD, strlen ($TempD));
}
}
echo "<pre>$buf</pre>\r\n<br>\r\n";
socket_close ($Thesocket);
} while (true);
socket_close ($sock);
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
<a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts. FREE! Go There Now!
|
|
|
|
You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
You can now evaluate IBM Rational Asset Manager V7.0 online without installing or configuring it on your own system! Rational Asset Manager helps create, modify, govern, find, and reuse any type of development assets, including SOA and systems development assets. Rational Asset Manager helps you reduce software development costs and improve quality by facilitating the reuse of all types of software development-related assets. Visit developerWorks to learn more about this product and register to explore its capabilities online. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |