Writing Headers and HTTP POST Body to a File

From Second Life Wiki
Revision as of 18:34, 13 June 2016 by Draconis Neurocam (talk | contribs) (Added PHP)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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>