Sending data from Second Life to the web

Written by: Headmaster

Written by Kahiro Watanabe

 

If you are an LSL coder then you know that LSL scripts have little memory (64 k as of February 13 2010) and there’s no way to store larges amount of data or store sensible data and keep it safe. The only way to achieve this is by sending it out of the grid and store it somewhere in the World Wide Web. In this post I will explain you how to do that from scratch without any previous knowledge in PHP or HTML, let’s see how it goes!.

Q: What are we going to do?

A: We are going to send data from an LSL script in Second Life to a PHP script. For this we are going to use the llHTTPRequest function

The lsl script:

 

key myRequest;
default
{
    touch_start(integer number)
    {
           myRequest = llHTTPRequest("http://www.mysite.com/index.php",[HTTP_METHOD, "POST",HTTP_MIMETYPE, "application/x-www-form-urlencoded"],"name=Jane&age=22");
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
            if (request_id == myRequest)
            {
                  llSay(0,body);
            }
    }
}

 Output: Jane is 22 years old

 

 

The PHP Script:

 

 

index.php

 

 

In this example we learned how easy is to send data from an LSL script to an url, in this case a PHP script and then return its values back again to SL.

The http_response method is simply used to know what happens after you send the data and keys are used to handle different requests, I’ll show you an example of that in future posts.

 

Category: