Difference between revisions of "User:Opensource Obscure/http"

From Second Life Wiki
Jump to navigation Jump to search
(New Upcoming HTTP-in Features - Example: Web Form to send messages in-world from a webpage)
m (templatizationingsx)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[User:Opensource_Obscure|BACK to User:Opensource_Obscure]]
{{User:Opensource_Obscure/Backlink}}


* [[User:Opensource Obscure/http/gridurl-sample]] a sample script that shows how to use Gridurl to get persistent URLs while using LSL HTTP Server.
* [[User:Opensource_Obscure/Chromutate]] a web-based, dynamic installation that can be controlled from a web page. Uses Gridurl.


== Web Form to send messages in-world from a webpage ==
Old projects (deprecated):
 
* [[User:Opensource_Obscure/http/snurl-sample]]
The following LSL script requests a new LSL Server public URL, then makes an HTTP call that updates a DB with the public URL of the script. A form read the URL from the DB and lets users send a message from a web page to the script.
* [[User:Opensource_Obscure/http/text-db]]
<br>
It supports an automatic system to work around the dynamic URL problem. This requires a web hosting with PHP/MySQL support and a field in a database.
<br>It sort-of works (only in a few sims on the beta grid!), but it's not complete yet; also, it's probably horrible code, I'm not a developer - don't use this if you don't know what you're doing.
 
 
== LSL code ==
 
<lsl>
    string my_url;
    key http_request_id;
    string base_url = "http://..../update.php?q="; // LA TUA PAGINA PHP
 
    default
    {
        state_entry()
        {
            llRequestURL();   
        }
 
        http_request(key id, string method, string body)
        {
            if (method == URL_REQUEST_GRANTED)
            {
                my_url = body;
                llOwnerSay("chiamero' questo indirizzo: " + base_url + my_url);
                llSetObjectDesc(my_url);
                http_request_id = llHTTPRequest(base_url + my_url, [HTTP_METHOD, "POST"], "");           
            }
            else if (method == URL_REQUEST_DENIED)
            {
                llOwnerSay("Errore: non ricevo il mio URL. " + body);
            }
            else if (method == "GET")
            {
                string text = llGetHTTPHeader(id, "x-query-string");
                llSetText(text, <1,1,1>, 1);
                llHTTPResponse(id,200,"OK!");
                llSay(0, "sono stato chiamato da web");
            }
            else
            {
                llHTTPResponse(id,405,"Unsupported Method");
            }
        }
 
        touch_start(integer total_number)
        {
            llOwnerSay("Il mio URL e': " + my_url);
            http_request_id = llHTTPRequest(base_url + my_url, [], "");         
        }
 
 
        http_response(key request_id, integer status, list metadata, string body)
        {
            if (request_id == http_request_id)
            {
                // llInstantMessage(llGetOwner(), body);
            }
        }     
 
 
    }
</lsl>
 
 
== HTML / PHP code ==
<lsl>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
 
    <body>
 
    <?php
    include 'config.php';
    include 'opendb.php';
 
    $query  = "SELECT * FROM `http-in`";
    $result = mysql_query($query);
 
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        echo "<a href=\"{$row['url']}\">{$row['url']}</a><br><br>";
        $newurl = $row['url']."/test";
    }
 
    include 'closedb.php';
    ?>
 
 
    <form action ="<?php echo $newurl ?>" method="get">
    <input name="text">
    <input type="submit">
    </form>
 
    </body>
    </html>
</lsl>

Latest revision as of 04:13, 22 April 2011

Go back to Opensource Obscure's userpage



Old projects (deprecated):