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! |
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!
|
|
|
|
Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right." FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
|
|
|
|
User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges. FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |