Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llHTTPRequest

Smithy Zeno
ownes 9 pet cacti
Join date: 3 Aug 2006
Posts: 52
11-11-2007 12:52
Hey all,
I've gotten my own website (finally) but I want to know how to make it communicate with SL. All I really want it to do is have it so that when I touch the object, the object sends the data (string) to the website and the web page uses echo to make it appear. I'm not good with PHP, so if someone could write me a small amount of code or send me in the right direction, that'd be great. Thanks in advance.

CODE

string name = "Testing!";

default
{
state_entry()
{
llResetScript();
}

touch_start(integer total_number)
{
llHTTPRequest("http://skullgraber.lllantlll.com/URL.php",[HTTP_METHOD,"POST"],name);
}
}
_____________________
-Smithy
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
11-11-2007 13:41
if you send php something and then go look at it, that something will not be there, it only works for that one original session, so you have to store the data somewhere (flat file or a database)

this seemed to be helpfull in another post about basicly the same thing... altho its not advised to use in production

/54/0c/205116/1.html#post1641083
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
11-12-2007 04:59
Yeah that version works but as Osgeld said it doesn't have any security so the only protection is that no-one knows the name of the file you are creating.

Another way to do this would be to use an MySQL database to store the info. Databases are password protected as far as I'm aware so it's a little more secure. Of course this also increases your workload in terms of scripting. I have an example of the lsl and php needed to do this so but it's at home and I'm at work. IM me or wait for me to get home to post the code:)

ooops didn't read OP properly. The scripts I've got won't echo the results back to SL but I will still happily share what I have.


The LSL code (the bit your interested in is the llHTTPRequest)

CODE

integer price = 400;
key req_id2;
string lname;
default
{
state_entry()
{
//Set up quick pay
llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
}
run_time_permissions(integer perm)
{

//Get owner debit permissions
if(perm & PERMISSION_DEBIT)
state cash;
}
}

state cash //with perms set up price
{
state_entry()
{
llSetPayPrice(PAY_HIDE, [price ,PAY_HIDE, PAY_HIDE, PAY_HIDE]);
}
money(key id, integer amount) //when paid do this
{
if(amount != price)//if not paid the right amount refund the amount
{
llGiveMoney(id, amount);
llInstantMessage(id, "You paid "+(string)amount+", which is the wrong price, the price is: "+(string)price);
}

else //if paid the right amount do this
{
lname = llKey2Name(id); //Get the payers key

//This bit sends the info to the PHP file on my server

req_id2 = llHTTPRequest("http://mywebsite.com/my_php_file.php", [HTTP_METHOD,"POST", HTTP_MIMETYPE,"application/x-www-form-urlencoded"], "name=" + lname + "&key=" + (string)id);

llInstantMessage(id, "You paid the right price");//Confirm amount

llGiveInventory(id, "my_item");//give item

llEmail("myaddress@host.com","sales","my message" +llKey2Name(id)); // email me with what I sold and who to
}
}
}



The PHP code

CODE

<?php

$username="my_user_name";
$password="my_password";
$database="localhost";
$db="my_database";

$name = $_POST['name'];
$key = $_POST['key'];
$table = "my_table";

$conection = mysql_connect($database,$username,$password);
mysql_select_db($db, $conection) or die( "Unable to select database");

$query = "INSERT INTO `my_table` (`name`, `key`) VALUES ('".$name."', '".$key."')";

mysql_query($query) or die(mysql_error());
mysql_close();
?>



Sorry I don't have the echo info in there but it gives you an idea of how the info is passed around.

You will need to be able to host mysql on your site for this to work and set up a databse and table for the info to go in
_____________________
Tread softly upon the Earth for you walk on my face.
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
11-12-2007 07:10
You might want to take a read through this thread:
/54/3c/220594/1.html
Where, together with other scripters, I try to help Cherry with getting started using HTTPRequest and a MySQL database. I tried to let Cherry discover the answers herself or ask the right questions without being bombarded with all the information en mass. Any difficulties with anything just give us a shout and we usually do what we can to help.
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum