Difference between revisions of "User:Opensource Obscure/http"
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]] | ||
<br>This | == 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> | ||
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) | |||
{ | { | ||
llOwnerSay(" | 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> | </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>