Writing Headers and HTTP POST Body to a File

From Second Life Wiki
Jump to navigation Jump to search
 
<!DOCTYPE html>
<html>
    <head>
        <title>LSL Test Page</title>
    </head>
<body>
    <p> 
        <?php                 
                $headers = apache_request_headers();                
                function test_input($data) 
                {
                  $data = trim($data);
                  $data = stripslashes($data);
                  $data = htmlspecialchars($data);
                  return $data;
                } 
                if ($_SERVER["REQUEST_METHOD"] == "POST" && $headers["X-Secondlife-Shard"] == "Production") 
                {
                    $pdata=nl2br(implode("\n", $headers));
                    foreach ($headers as $header => $value) 
                    {
                        $headersindiv.= "$header: $value <br />\n";
                    }
                    $input=file_get_contents("php://input");
                    $pdata = test_input($input);
                    $headersindiv.=$pdata;
                    
                    $wfile = fopen("lslget.txt", "w") or die("Unable to open file!");
                    fwrite($wfile, $headersindiv);
                    fclose($wfile);
                    $file='lslget.txt';
                    if(filesize($file)>0)
                    {
                        $readfile=fopen($file, "r") or die("Unable to open file!");
                        echo fread($readfile,filesize($file));
                        fclose($readfile); 
                    }
                }
         ?> 
    </p>
</body>
</html>
key httpreq(string page,string MSG)
{
    return llHTTPRequest(page,[
                                HTTP_METHOD,
                                            //"GET" 
                                            "POST" 
                                            //"PUT" 
                                            //"DELETE" 
                                            ,
                                HTTP_MIMETYPE,
                                                "text/application/xhtml+xml"
                                                //"text/application/atom+xml"
                                                //"text/application/json"
                                                //"text/application/xml"
                                                //"text/application/llsd+xml"
                                                //"text/application/x-javascript"
                                                //"text/application/javascript"
                                                //"text/application/x-www-form-urlencoded"
                                                //"text/application/rss+xml"
                                                ,
                                HTTP_BODY_MAXLENGTH,16384,
                                HTTP_VERIFY_CERT,TRUE,
                                HTTP_VERBOSE_THROTTLE,TRUE,
                                //HTTP_CUSTOM_HEADER,"","",
                                HTTP_PRAGMA_NO_CACHE,TRUE
                            ],MSG);
}
key reqed;
default
{
    touch_start(integer total_number)
    {
        reqed=httpreq( "yourfile.php/","body text");
    }
    http_response(key request_id, integer status, list metadata, string body)
    {
        if(reqed==request_id)
        {
            llOwnerSay(body);      
        }
    }
}