Jump to content

Posting to webserver


XbabylonX
 Share

You are about to reply to a thread that has been inactive for 4273 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

It's  bit diffucult to help you on your problem with the information you provided.

You say, you have a script, that receives data from a POST request successfully

  • What do you mean by saying, it receives the data successfully?
  • What is the script on the server written in?
  • If you say, it receive the data with success, what do you actually mean when you later state that 'the page can't take it'?
Link to comment
Share on other sites

Hello,

the sl script gathers some information and then it calls a webpage (.php) to post them in my db (mysql).

This sl script triggers normally my webpage, but my webpage doesnt takes the data. 

$_POST["sldata"] cant take the data.

Thank you for your answer :matte-motes-bashful-cute-2:

 

Link to comment
Share on other sites

Ok - if I understand you corecttly, you send a post request to the php - and the php is called - but the php doesn't read the data from the $_POST array correctly - right?

Could you five an example of how the body of your request looks?

Are you sure the php doesn't read the data correctly, or could it be something in your SQL statements? In other words, how do you know that the php gets called but doesn't retrieve the data?

Link to comment
Share on other sites

That wouldn't make too much sense, since request in the most cases come from other IPs or domains.

Take it step by step.

First, make a simple request with just a simple value like "test=myTest" and have the php just echo $_POST['test'] and see if the right value is returned to your LSL script. I'm almost sure, you have a little error somewhere. Always try to track things down by taking simple steps.

Link to comment
Share on other sites

When it works, add this to the php file at the top:

function gethostbyaddr_timeout($ip,$timeout=2){    $host=`host -W $timeout $ip`;        if(preg_match('`in-addr.arpa domain name pointer (.*)\.\n$`i',$host,$matches))    {        $host=$matches[1];    } else {        $host=$ip;    }    return $host;}$dom = gethostbyaddr_timeout($_SERVER['REMOTE_ADDR']);$ip = gethostbyname($dom);if(!preg_match('`^.*\.lindenlab\.com$`',$dom) || $ip!=$_SERVER['REMOTE_ADDR']){    print '<center>No outworld access allowed</center>';    exit;}

 

Link to comment
Share on other sites

The code snippet is simply to prevent any access to the web page unless originating from within sl, add it to the top of the php page befor executing your code, if it is not originating from the sl domain then it simply exits with a message.

To fix your issue, you will really need to provide alot more information, like part of the script and php file as it is otherwise impossible to even guess what the problem might be

Link to comment
Share on other sites

After Minotaur notices I came up with the following

float TIME_FRAME = 30.0; // Set detection time frame in secondsfloat DETECTION_RANGE = 60.0; // Set the detection radius of the sensor in metersinteger TEST_MODE = TRUE; // TRUE for test mode on, FALSE for actually posting datalist avatars;post_data(){string POST_URL = "http://www.domain.com/execute.php";string query_string = "Avatars=";string separator = ",";while (llGetListLength(avatars) > 0){if (llGetListLength(avatars) <= 1){separator = "";}query_string += llList2String(avatars, 0) + separator;avatars = llDeleteSubList(avatars, 0, 0);}if (TEST_MODE){llOwnerSay(query_string);}else {llHTTPRequest(POST_URL, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], llEscapeURL(query_string));}}default{state_entry(){llSensorRepeat("", NULL_KEY, AGENT, 60.0, PI, TIME_FRAME);}no_sensor(){avatars = [];post_data();}sensor(integer total_number){integer i;avatars = [];do {avatars = (avatars=[]) + avatars + [llDetectedName(i)];} while (++i < total_number);post_data();}}

 

 

Here is my php code

 

function gethostbyaddr_timeout($ip,$timeout=2){$host=`host -W $timeout $ip`; if(preg_match('`in-addr.arpa domain name pointer (.*)\.\n$`i',$host,$matches)){$host=$matches[1];} else {$host=$ip;}return $host;}$dom = gethostbyaddr_timeout($_SERVER['REMOTE_ADDR']);$ip = gethostbyname($dom);if(!preg_match('`^.*\.lindenlab\.com$`',$dom) || $ip!=$_SERVER['REMOTE_ADDR']){print '<center>No outworld access allowed</center>';exit;}$user_name = "username";$password = "password";$database = "database";$server = "127.0.0.1";$db_handle = mysql_connect($server, $user_name, $password);$db_found = mysql_select_db($database, $db_handle);if ($db_found) {$SQL = "REPLACE INTO Test (Test) VALUES ('" . $_POST["Avatars"] . "')";$result = mysql_query($SQL);mysql_close($db_handle);}else {mysql_close($db_handle);}

 

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4273 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...