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

From Second Life Wiki
Jump to navigation Jump to search
m
(New Upcoming HTTP-in Features - Example: Web Form to send messages in-world from a webpage)
Line 1: Line 1:
[[User:Opensource_Obscure|BACK to User:Opensource_Obscure]]
[[User:Opensource_Obscure|BACK to User:Opensource_Obscure]]


With this script, a prim requests a new LSL Server public URL, then makes a http call that updates a db with the prim's public URL.
 
<br>This is probably horrible, I can't code, don't use this if you don't know what you're doing.
== Web Form to send messages in-world from a webpage ==
 
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.  
<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>
<lsl>
default
    string my_url;
{
     key http_request_id;
     state_entry()
     string base_url = "http://..../update.php?q="; // LA TUA PAGINA PHP
     {
 
llSay(0, "clean this script!");
     default
        llRequestURL();   
     }
    http_request(key id, string method, string body)
     {
     {
         if (method == URL_REQUEST_GRANTED)
         state_entry()
         {
         {
             a = body;
             llRequestURL();    
            llOwnerSay("chiamo: " + url+a);
            llSetObjectDesc(a);
            http_request_id = llHTTPRequest(url+a, [HTTP_METHOD, "POST"], "");            
         }
         }
         else if (method == URL_REQUEST_DENIED)
 
         http_request(key id, string method, string body)
         {
         {
             llOwnerSay("Something went wrong, no url. " + 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");
            }
         }
         }
         else if (method == "GET")
 
         touch_start(integer total_number)
         {
         {
             string text = llGetHTTPHeader(id, "x-query-string");
             llOwnerSay("Il mio URL e': " + my_url);
             llSetText(text, <1,1,1>, 1);
             http_request_id = llHTTPRequest(base_url + my_url, [], "");          
            llHTTPResponse(id,200,"OK! Please click BACK in your browser");
            llSay(0, "called by web");
         }
         }
         else
 
 
         http_response(key request_id, integer status, list metadata, string body)
         {
         {
             llHTTPResponse(id,405,"Unsupported Method");
             if (request_id == http_request_id)
         }
            {
                // llInstantMessage(llGetOwner(), body);
            }
         }      
 
 
     }
     }
   
</lsl>
     touch_start(integer total_number)
 
 
== 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))
     {
     {
         llOwnerSay("MY URL: " + a);
         echo "<a href=\"{$row['url']}\">{$row['url']}</a><br><br>";
        llSetObjectDesc(a);      
         $newurl = $row['url']."/test";
         http_request_id = llHTTPRequest(url+a, [], "");          
     }
     }
    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == http_request_id)
        {
            // llInstantMessage(llGetOwner(), body);
        }
    }       
}


    include 'closedb.php';
    ?>
    <form action ="<?php echo $newurl ?>" method="get">
    <input name="text">
    <input type="submit">
    </form>
    </body>
    </html>
</lsl>
</lsl>

Revision as of 15:32, 22 February 2009

BACK to User:Opensource_Obscure


Web Form to send messages in-world from a webpage

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.
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.
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>

"; $newurl = $row['url']."/test"; }
   include 'closedb.php';
   ?>


   <form action ="<?php echo $newurl ?>" method="get">
   <input name="text">
   <input type="submit">
   </form>
   </body>
   </html> 

</lsl>