Don't click here unless you want to be banned.

LSL Wiki : ExamplellHTTPRequest

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ec2-50-19-148-56.compute-1.amazonaws.com
This is a minimalistic approach to setting up a simple request to a remote web server, and get the result.

Limitations: apparently PHP must be compiled as an Apache module (and not using FastCGI) for you to get access to apache_response_headers().
Note: There is an PHP based emulation to the apache_response_headers() while using FastCGI emu_getallheaders()

key requestid; // just to check if we're getting the result we've asked for; all scripts in the same object get the same replies

default
{
    touch_start(integer number)
    {
        requestid = llHTTPRequest("http://my.server.com/my-script.php", 
            [HTTP_METHOD, "POST",
             HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
            "parameter1=hello&parameter2=world");
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == requestid)
            llWhisper(0, "Web server said: " + body);
    }
}

And here goes myscript.php:

<?
// Only works with PHP compiled as an Apache module
$headers apache_request_headers();

$objectName $headers["X-SecondLife-Object-Name"];
$objectKey     $headers["X-SecondLife-Object-Key"];
$ownerKey     $headers["X-SecondLife-Owner-Key"];
$ownerName $headers["X-SecondLife-Owner-Name"];
$region        $headers["X-SecondLife-Region"];
// and so on for getting all the other variables ...

// get things from $_POST[]
// Naturally enough, if this is empty, you won't get anything
$parameter1    $_POST["parameter1"];
$parameter2    $_POST["parameter2"];

echo 
$ownerName " just said " $parameter1 " " $parameter2 "\n";
?>

Note: if for some reason $_POST[] doesn't return anything, you have to check for other alternatives, like the one described on the first comment on the page for llHTTPRequest (directly reading from the HTTP stream), as per VeloxSeverine's suggestion.

Suggestion: Use $_REQUEST[] instead of $_POST[] as it will work for all types, as well as, POST. SiRiSAsturias

Note: For greater server compatibility and efficiency, use $_SERVER[] instead of apache_request_headers() to access the SL header data. For Example, $_SERVER['HTTP_X_SECONDLIFE_OWNER_NAME']; (notice the format change of the data labels) ~PlexLum

Example: Here is the use of a emulated apache_request_headers() that I wrote; if you're using FastCGI and are used to using the apache function, use this! I hope this helps someone! (It'll also allow you to get the headers if you're not using FastCGI). FoxDiller
Small edit to correct the casing of X-SecondLife headers, as variable names and array keys in PHP are case sensitive. (And in case anyone is wondering, this function also works with PHPSuExec too) - EddyOfarrel
<?php
function emu_getallheaders()
{
    foreach(
$_SERVER as $name => $value)
    if(
substr($name05) == 'HTTP_')
        
$headers[str_replace('X-Secondlife-''X-SecondLife-'str_replace(' ''-'ucwords(strtolower(str_replace('_'' 'substr($name5))))))] = $value;
    return 
$headers;
}

$headers emu_getallheaders(); // Just replace any use of `apache_request_headers()` with `emu_getallheaders()`.

$objectName $headers["X-SecondLife-Object-Name"];
$objectKey $headers["X-SecondLife-Object-Key"];
// ..........................[~ETC ETC~]..........................//
?>

I have been asked to offer my source code for checking HTTP headers, so I present yet another example... the server and client code to check headers... - Ice
<?php
//This simply echoes the headers exactly as it gets them...
//This script requires PHP as an apache module to work

$headers=apache_request_headers();
foreach(
$headers as $key => $val)
{
     echo 
$key.": ".$val."\n";
}
?>
//Ice Brodie's http text output script
//This script requests from our data source (URL) and echoes out what it sends to the owner of the script
//I use this to test my PHP apps personally, it's a simple debugging application so I release it publicly
//You may use, redistribute, modify, copy however you feel would be useful

string URL="http://www.secondlife.com/httprequest/homepage.php";
//Replace URL with the path to your web server.
key http;//This stores the HTTP request we send.

default
{
    touch_start(integer foo)
    {
        http=llHTTPRequest(URL, [] ,"");
    }

    http_response(key id,integer status, list meta, string body)
    {
        if(http==id)
        {
            integer i;
            list lbody=llParseString2List(body,["\r\n","\n"],[]);
            integer count=llGetListLength(lbody);
            //This turns newline characters char(10) into new lines in chat
            // Fixed Dec 8, 2008: Now parses both Unix and Windows style end of lines
            //    Though RFC requires Unix style, this becomes more tolerant.
            for(i=0;i<count;i++)
            {
                llOwnerSay(llList2String(lbody,i));
            }
        }
    }
}
--
Examples | Jasa SEO Murah Jasa SEO Jasa Google Adwords Jasa Adwords Google Adwords Sepatu Safety Sepatu Futsal Cheapes Hostgator Coupon Link Booking Televisori offerte Notebook Offerte Govr Edo Ziedo Portatile Apple RDAnet Lorks Karikatur Bisnis Modal Kecil Bisnis UKM Berita Terbaru Iklan Baris Jasa SEO Murah SEO Indonesia Konsultan SEO SEO Belajar SEO Penumbuh Rambut Kursus SEO Jam Tangan Casio Grosir Baju Bisnis Online Kerupuk Kulit Social Bookmark Kumpulan Puisi WBC Wonogiri Penumbuh Rambut Jam Tangan Murah Jam Tangan Murah Jam Tangan Casio Penumbuh Rambut Kerupuk Kulit Alat Kantor Laku.com Belanja Online Grosir Eceran Murah dan Aman Jasa SEO Model Jilbab Fine Tableware Permanent Hair Removal island investment development professional makeup artist bali private villa sewa mobil jakarta murah Jual rumah Jakarta Contact Lens Technology
There are 3 comments on this page. [Display comments/form]