<?php
error_reporting(E_ALL);

$service_port = 1995;

$address = gethostbyname('localhost');

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
    echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n<BR>";
} else {

}

$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
    echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n<BR>";
} else {

}

if(strcmp($_SERVER["REQUEST_METHOD"], "GET") == 0) {
   $in = $_SERVER["QUERY_STRING"] . "&embed=true\n";
}
else {
   $in = "";
   foreach($_POST as $id => $val) {
      if(strcmp($in, "") != 0)
         $in .= "&";
      $in = urlencode($id) . "=" . urlencode($val);
   }
   if(strcmp($in, "") == 0)
      $in ="&embed=true\n";
   else 
      $in .="&embed=true\n";
}
$out = '';

socket_write($socket, $in, strlen($in));

$page = "";

while ($out = socket_read($socket, 2048)) {
    $page .= $out;
}

print $page;

socket_close($socket);
?> 
