Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llHTTPRequest(), POST data and PHP

Peccable Peck
Registered User
Join date: 27 May 2006
Posts: 2
06-10-2006 00:22
Hiya.

I'm trying to pass a string to a PHP script via llHTTPRequest(url, [HTTP_METHOD,"POST"], myString).

I've never used PHP before and thus have no idea how to get to the data in myString. Does anyone have any code snippets that illustrate how to get to these variables?

Thanks!
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
06-10-2006 16:22
Well I don't know PHP but this may help.

If you POST the data string as the body, then the string will have to be read from the input stream of the POST request at the server side (i.e. it won't appear as http request parameters).

You could alternatively append a query string to the URL.

/esc
_____________________
http://slurl.com/secondlife/Together
Derander Witte
Registered User
Join date: 23 Apr 2006
Posts: 7
06-10-2006 16:27
Well.. not good business sense, but in the interest of education:

Using the get method is much easier.

Simply append ?varname=value&varname2=value2...to infinity to your url to send data to that php script

Then, have that php script read data from:

$_GET['varname'];
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
06-10-2006 16:36
...yes true, except urls have a limited length and so a GET query string may lead to corrupt data...
_____________________
http://slurl.com/secondlife/Together
Peccable Peck
Registered User
Join date: 27 May 2006
Posts: 2
06-10-2006 17:03
What I finally found that worked:

<?php
header("Content-type: text/plain; charset=UTF-8";);

// taken from the comments on the llHTTPRequest wiki page
$p_data = implode('', file('php://input'));
$p_data = explode('&', $p_data);
foreach ($p_data as $p_val)
{
$d_parts = explode('=', $p_val);
$_POST[$d_parts[0]] = urldecode($d_parts[1]);
}

// to put results out to a file
$fp = fopen ( 'myOutput.txt', "w";);
fwrite($fp, print_r($_POST, true));
fclose($fp);

// to assign values
$phpVar = $_POST["slVar"];

//dynamic values (where is $i is an integer)
$phpVarDyn = $_POST["slVar" . $i];

?>

My body in LSL was filled with key value pairs, identical to a url's query string. E.g.: key1=value1&key2=value2&key3=value3&keycount=3

Adding a keycount allowed me to loop through the keys using the 'dynamic values' syntax above.

I spent much too long putting all this information together so I hope it comes in handy for someone else.
SiRiS Asturias
Chaotic Coder
Join date: 27 Sep 2005
Posts: 93
More Examples...
06-12-2006 07:23
The link below shows basic, fast examples for PHP & ASP.Net2.0:

http://forums.secondlife.com/showth...611#post1086611

Enjoy! :p
_____________________
Proud founder of:
S3 - Self Storage Systems
S3storage.net (Coming Soon!)

SLBoutique.com
SLExchange.com - Find What You Need, When You Need It.

"Light travels faster than sound. This is why some people appear bright, until you hear them speak."