<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.secondlife.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Grid+Wise</id>
	<title>Second Life Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.secondlife.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Grid+Wise"/>
	<link rel="alternate" type="text/html" href="https://wiki.secondlife.com/wiki/Special:Contributions/Grid_Wise"/>
	<updated>2026-07-28T08:22:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.secondlife.com/w/index.php?title=HTTP_Post_request_to_a_PHP_server&amp;diff=10857</id>
		<title>HTTP Post request to a PHP server</title>
		<link rel="alternate" type="text/html" href="https://wiki.secondlife.com/w/index.php?title=HTTP_Post_request_to_a_PHP_server&amp;diff=10857"/>
		<updated>2007-02-19T00:19:52Z</updated>

		<summary type="html">&lt;p&gt;Grid Wise: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
LSL now offer the ability to request HTTP page from any website.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use different methods to access your webserver.&lt;br /&gt;
The most obvious is GET, the get method allows any number of parameters.&lt;br /&gt;
&lt;br /&gt;
The syntax is : &lt;br /&gt;
&lt;br /&gt;
http://www.yourwebsite.com/pay.php?user=Corto+Maltese&amp;amp;amount=100&lt;br /&gt;
&lt;br /&gt;
In the example above the page pay.php is requested with 2 parameters param1 and param2.&lt;br /&gt;
The issue with GET is that if someone manage to sniff or guess your webpage, he could potentially take any webbrowser and type : &lt;br /&gt;
&lt;br /&gt;
http://www.yourwebsite.com/pay.php?param1=Joe+Blog&amp;amp;amount=1000000&lt;br /&gt;
&lt;br /&gt;
And your web server will have little idea that this request is bogus.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is where my library comes into action.&lt;br /&gt;
&lt;br /&gt;
The LSL library takes every character in your HTTP request and compute a security HashCode.&lt;br /&gt;
The library will then add this extra security hash parameter to your request like that:&lt;br /&gt;
&lt;br /&gt;
http://www.yourwebsite.com/pay.php?user=Corto+Maltese&amp;amp;amount=100&amp;amp;hash=edabcc1792b33e7d6055cc4c8e69912c&lt;br /&gt;
&lt;br /&gt;
When the server receive the request, it will be able to check that the hash provided is correct.&lt;br /&gt;
If the request was tempered, the hash will not be correct, the server will therefore ignore the request and not allow Job Blog to pretend he has paid L$ 1,000,000.&lt;br /&gt;
&lt;br /&gt;
Also the library uses a POST method, the POST method is not very different from GET but allow slightly more input parameters than GET, The POST method is also a bit more secure as the parameters do not appears in the cache statistics or similar tools.&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&lt;br /&gt;
The main LSL function is called xrequest&lt;br /&gt;
&lt;br /&gt;
   xrequest(string Url, List Parameters)&lt;br /&gt;
&lt;br /&gt;
Url : &lt;br /&gt;
   is the address of your webpage. for example &amp;quot;http://www.yoursite.com/sl.php&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Parameters :&lt;br /&gt;
   is a list of string, the list must be set in pairs using this format: &lt;br /&gt;
   [variable_name_1, variable_value_1, variable_name_2, variable_value_2, ...]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the example below the script request a page using the parameters a=1, b=2 and c=3.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  default&lt;br /&gt;
  {&lt;br /&gt;
      touch_start(integer total_number)&lt;br /&gt;
      {&lt;br /&gt;
          xrequest(&amp;quot;http://www.yoursite.com/sl.php&amp;quot;,[&amp;quot;a&amp;quot;,&amp;quot;1&amp;quot;,&amp;quot;b&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;c&amp;quot;,&amp;quot;3&amp;quot;]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      http_response(key request_id, integer status, list metadata, string body)&lt;br /&gt;
      {&lt;br /&gt;
          if (request_id == http_request_id)&lt;br /&gt;
          {&lt;br /&gt;
              llSetText(body, &amp;lt;0,0,1&amp;gt;, 1);&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is the code of the xrequest function.&lt;br /&gt;
Note that you should change the SECRET_NUMBER to any number of your choice but preferably something rather large and random up to 2,000,000,000.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  integer SECRET_NUMBER=123456789;&lt;br /&gt;
  &lt;br /&gt;
  xrequest(string url, list l)&lt;br /&gt;
  {&lt;br /&gt;
      integer i;&lt;br /&gt;
      integer len=llGetListLength(l) &amp;amp; 0xFFFE; // makes the list count even&lt;br /&gt;
      string body;&lt;br /&gt;
  &lt;br /&gt;
     for (i=0;i&amp;lt;len;i+=2)&lt;br /&gt;
     {&lt;br /&gt;
          string varname=llList2String(l,i);&lt;br /&gt;
          string varvalue=llList2String(l,i + 1);&lt;br /&gt;
          if (i&amp;gt;0) body+=&amp;quot;&amp;amp;&amp;quot;;&lt;br /&gt;
          body+=llEscapeURL(varname)+&amp;quot;=&amp;quot;+llEscapeURL(varvalue);&lt;br /&gt;
      }&lt;br /&gt;
      string hash=llMD5String(body,SECRET_NUMBER);&lt;br /&gt;
      http_request_id = llHTTPRequest(url+&amp;quot;?hash=&amp;quot;+hash,[HTTP_METHOD,&amp;quot;POST&amp;quot;,HTTP_MIMETYPE,&amp;quot;application/x-www-form-urlencoded&amp;quot;],body);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On the server side here is the PHP function which will allow your server to check the securty hash:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  &amp;lt;?php&lt;br /&gt;
  function checkHash()&lt;br /&gt;
  {&lt;br /&gt;
  	$hash=$_GET[&amp;quot;hash&amp;quot;];&lt;br /&gt;
  	$body=&amp;quot;&amp;quot;;&lt;br /&gt;
  	$cpt=0;&lt;br /&gt;
  	$SECRET_NUMBER=123456789;&lt;br /&gt;
  	foreach ($_POST as $name =&amp;gt; $value) {&lt;br /&gt;
  		if ($cpt++&amp;gt;0) $body.=&amp;quot;&amp;amp;&amp;quot;;&lt;br /&gt;
  		$body.=urlencode($name).&amp;quot;=&amp;quot;.urlencode($value);&lt;br /&gt;
  	}&lt;br /&gt;
  	$calcHash=md5(&amp;quot;$body:$SECRET_NUMBER&amp;quot;);&lt;br /&gt;
  	if ($hash!=$calcHash)&lt;br /&gt;
  	{&lt;br /&gt;
  		//sleep(2); // slow down the requests&lt;br /&gt;
  		echo &amp;quot;result=FAIL\nMSG=Invalid hash&amp;quot;;&lt;br /&gt;
  		die;&lt;br /&gt;
  	}&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  checkHash();&lt;br /&gt;
  // You can use the parameters here by simply using $_POST[&amp;quot;parameter_name&amp;quot;] &lt;br /&gt;
  echo &amp;quot;OK&amp;quot;;&lt;br /&gt;
  ?&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This library could be improved, to treat output parameter too.&lt;br /&gt;
It doesn&#039;t do anything in this area yet.&lt;/div&gt;</summary>
		<author><name>Grid Wise</name></author>
	</entry>
</feed>