LoopFuse PHP Script Post
From LoopFuse Wiki
The following sample script enables socket-based communication with LoopFuse, allowing you to post form registration information to LoopFuse from a PHP script on the backend.
///////////////////////////////////////////////////////
// Send it to loopfuse
///////////////////////////////////////////////////////
//cycle through all the _POST variables in the form
while (list($result_name, $result_value) = each($_POST)) {
//uncomment the below for debugging
//echo $result_name . ":" . $result_value . "
";
//put all the variables in the format to send to loopfuse
$loopdata .= $result_name . "=" . $result_value . "&";
}
//remove the last &
$loopdata = substr($loopdata,0,(strlen($loopdata)-1));
//for debugging: view what you are sending to loopfuse, make sure it includes the vid variable
//echo "Var List: " . $loopdata . "
";
//send the information via the sendToHost function
$buffer = sendToHost("loopfuse.net","POST","/webrecorder/post",$loopdata);
//for debugging: uncomment the below to see what loopfuse sends back, we want to see a 200 code
//echo "Loopfuse's response: " . $buffer . "
";
The function that does all the work:
/* sendToHost
* 08:44, 12 March 2008 (CDT)08:44, 12 March 2008 (CDT)
* Params:
* $host - Just the hostname. No http:// or
/path/to/file.html portions
* $method - get or post, case-insensitive
* $path - The /path/to/file.html part
* $data - The query string, without initial question mark
* $useragent - If true, 'MSIE' will be sent as
the User-Agent (optional)
*
* Examples:
* sendToHost('www.google.com','get','/search','q=php_imlib');
* sendToHost('www.example.com','post','/some_script.cgi',
* 'param=First+Param&second=Second+param');
*/
//Used to send info to loopfuse
function sendToHost($host,$method,$path,$data,$useragent=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method)) {
$method = 'GET';
}
$method = strtoupper($method);
$fp = fsockopen($host, 80);
if ($method == 'GET') {
$path .= '?' . $data;
}
fputs($fp, "$method $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp,"Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
if ($useragent) {
fputs($fp, "User-Agent: MSIE\r\n");
}
fputs($fp, "Connection: close\r\n\r\n");
if ($method == 'POST') {
fputs($fp, $data);
}
while (!feof($fp)) {
$buf .= fgets($fp,128);
}
fclose($fp);
return $buf;
}
- Additional Notes:
- Make sure to include your formid and cid hidden variables in your form
- Make sure you have your listen.js code in the page where you have your form.
