XbabylonX Posted September 27, 2012 Share Posted September 27, 2012 Hello,I have a piece of a script which calls a webpage on my server (using post method) with success.The problem is that my page cant take the data I send.Could someone help me on that?The server is a linux.Thank you! Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted September 27, 2012 Share Posted September 27, 2012 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 More sharing options...
XbabylonX Posted September 27, 2012 Author Share Posted September 27, 2012 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 More sharing options...
Darkie Minotaur Posted September 27, 2012 Share Posted September 27, 2012 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 More sharing options...
XbabylonX Posted September 27, 2012 Author Share Posted September 27, 2012 In my sql statement I used a simple string to be inserted. Thats why I said that the sl script triggers my page as it should. Is it possible my server denies to grab the data I sent for security reasons? Because the posting page is not under the same domain? Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted September 27, 2012 Share Posted September 27, 2012 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 More sharing options...
XbabylonX Posted September 27, 2012 Author Share Posted September 27, 2012 I did that too. Sending a simple string with the sl script. But now that I mentioned security, dont you think that everyone could post in my webpage if they just know its name? Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted September 27, 2012 Share Posted September 27, 2012 I've you don't take any meassures: Yes, of course. Anyone can send a request to google.com - and if you know how to assemble the request, you will get a meaningful reply. It really would be helpful to post your simple lsl and the corresponding php here - there are simply too many possible traps. Link to comment Share on other sites More sharing options...
Alicia Sautereau Posted September 27, 2012 Share Posted September 27, 2012 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 More sharing options...
XbabylonX Posted September 27, 2012 Author Share Posted September 27, 2012 Hello ALicia, is this for securing the posting? I confess I expertise on win servers and not in linux. I just have to deal with linux this time! Link to comment Share on other sites More sharing options...
Luca Coeur Posted September 28, 2012 Share Posted September 28, 2012 Hello XbabylonX, the PHP code above is platform independent, so it is of no concern what OS you're using ;-) And yes, it is a way to restrict access to your PHP script to computers out of the secondlife.com domain. Good luck and have fun :-) Link to comment Share on other sites More sharing options...
XbabylonX Posted September 28, 2012 Author Share Posted September 28, 2012 Hello thank you for your answers, this script does nice job preventing any execution. But still I cant retrieve the data Link to comment Share on other sites More sharing options...
Alicia Sautereau Posted September 28, 2012 Share Posted September 28, 2012 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 More sharing options...
Darkie Minotaur Posted September 28, 2012 Share Posted September 28, 2012 The OP showed his code to me - and the mystery was resolved pretty quickly - he used the post method but placed the name value pairs in the url Link to comment Share on other sites More sharing options...
XbabylonX Posted September 29, 2012 Author Share Posted September 29, 2012 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 More sharing options...
Recommended Posts
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