<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Onestone</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Onestone"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Onestone"/>
	<updated>2026-05-02T17:45:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PHP_SDK&amp;diff=21070</id>
		<title>PHP SDK</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PHP_SDK&amp;diff=21070"/>
		<updated>2009-08-14T11:29:59Z</updated>

		<summary type="html">&lt;p&gt;Onestone: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
You can access the MTA Web Interface from almost any programming language that can request web pages using HTTP POST and encode and decode [[JSON]].&lt;br /&gt;
&lt;br /&gt;
PHP can do this very easily! This SDK provides one function &amp;quot;callFunction&amp;quot; that will allow you to call any exported script functions on any server that you have access to.&lt;br /&gt;
&lt;br /&gt;
The download below includes two example pages - one that shows a simple scoreboard, the other that shows the automatic handling of element and resource objects.&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
===call===&lt;br /&gt;
This function calls an exported function in a specific resource.&lt;br /&gt;
&lt;br /&gt;
'''Syntax:'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$mtaServer = new mta( $hostname, $port, $username, $password );&lt;br /&gt;
$resource = $mtaServer-&amp;gt;getResource ( $resourceName );&lt;br /&gt;
$returns[] = $resource-&amp;gt;call ( &amp;quot;functionName&amp;quot; [,args...] );&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===getInput===&lt;br /&gt;
This function is for use with web pages that are called by [[callRemote]].&lt;br /&gt;
&lt;br /&gt;
'''Syntax:'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
inputData[] = mta::getInput();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===doReturn===&lt;br /&gt;
Use this function when you want to return data when a page is called with [[callRemote]]. You should '''NOT''' output any other data to the page, e.g. using ''echo'' as this will cause the return to fail.&lt;br /&gt;
&lt;br /&gt;
'''Syntax:'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
mta::doReturn( argument1, argument2 ... argumentN );&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
include( &amp;quot;mta_sdk.php&amp;quot; );&lt;br /&gt;
$mtaServer = new mta(&amp;quot;bastage.net&amp;quot;, 33004);&lt;br /&gt;
$resource = $mtaServer-&amp;gt;getResource ( &amp;quot;echobot&amp;quot; );&lt;br /&gt;
$retn = $resource-&amp;gt;call ( &amp;quot;getThisResource&amp;quot; ); // $retn is an array containing the values the function returned&lt;br /&gt;
$resource = $retn[0]; // the first returned value is the resource&lt;br /&gt;
$retn = $resource-&amp;gt;call ( &amp;quot;getResourceName&amp;quot;, $resource ); &lt;br /&gt;
$resourceName = $retn[0]; // contains the name of the resource 'echobot'&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Authentication==&lt;br /&gt;
If the server you are accessing requires authentication, you must pass the ''http_username'' and ''http_password'' variables to your instantiated instance of the mta() class.&lt;br /&gt;
&lt;br /&gt;
'''Example:'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
include( &amp;quot;mta_sdk.php&amp;quot; );&lt;br /&gt;
$mtaServer = new mta(&amp;quot;example.com&amp;quot;, 33004, &amp;quot;myUsername&amp;quot;, &amp;quot;myPassword&amp;quot; );&lt;br /&gt;
$mtaServer-&amp;gt;getResource(&amp;quot;someResource&amp;quot;)-&amp;gt;call(&amp;quot;someFunction&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A page that can be called by [[callRemote]]==&lt;br /&gt;
This example just adds two numbers passed to it by a lua script.&lt;br /&gt;
&lt;br /&gt;
'''PHP:''' (for the page that LUA expects to be at ''&amp;lt;nowiki&amp;gt;http://www.example.com/page.php&amp;lt;/nowiki&amp;gt;'')&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
include( &amp;quot;mta_sdk.php&amp;quot; );&lt;br /&gt;
$input = mta::getInput();&lt;br /&gt;
mta::doReturn($input[0] + $input[1]);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
'''LUA:'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- result is called when the function returns&lt;br /&gt;
function result(sum)&lt;br /&gt;
    outputChatBox(sum)&lt;br /&gt;
end&lt;br /&gt;
function addNumbers(number1, number2)&lt;br /&gt;
    callRemote ( &amp;quot;http://www.example.com/page.php&amp;quot;, result, number1, number2 )&lt;br /&gt;
end &lt;br /&gt;
addNumbers ( 123, 456 ) -- call the function&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Caveats==&lt;br /&gt;
* This only works with PHP 5.0 and above.&lt;br /&gt;
* You cannot currently compare two Element instances that you expect to be identical - you need to do a &amp;quot;deep compare&amp;quot;, comparing either the &amp;quot;id&amp;quot; fields.&lt;br /&gt;
&lt;br /&gt;
==Download==&lt;br /&gt;
*[http://code.opencoding.net/mta/mtaphpsdk_0.3_fix.zip Download Version 0.3] - Neater syntax, support functions for [[callRemote]] (fix version makes call work with args).&lt;br /&gt;
*[http://misc.opencoding.net/mta/mtaphpsdk_0.2.zip Download Version 0.2] -  ''Deprecated - Syntax differs from examples shown above.'' - Adds authentication support&lt;br /&gt;
*[http://misc.opencoding.net/mta/mtaphpsdk_0.1.zip Download Version 0.1] - ''Deprecated - Syntax differs from examples shown above.''&lt;/div&gt;</summary>
		<author><name>Onestone</name></author>
	</entry>
</feed>