Location: PHPKode > scripts > CSecondLife > csecondlife/CSecondLife.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="http://www.w3.org/1999/xhtml">
	<title>The CSecondLife class</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

	<h1 id="thecsecondlifeclass">The <code>CSecondLife</code> class</h1>

	<p><code>CSecondLife</code> is a class that extracts information from HTTP requests that originate from <a href="http://secondlife.com">Second Life</a> objects. Through HTTP, you can have a Second Life object interact with a PHP backend to create complex in-world applications.</p>

	<p>For more information about making HTTP requests from within Second Life, see the documentation at the LSL Wiki for the <a href="http://www.lslwiki.net/lslwiki/wakka.php?wakka=llHTTPRequest">llHTTPRequest</a> function.</p>

	<h2 id="reference">Reference</h2>

	<h3 id="constructor">Constructor</h3>

	<pre><code>new CSecondLife();

	<p>The constructor initializes the <code>CSecondLife</code> instance&#8217;s properties. If it detects that the current request does not come from inside Second Life, it will not initialize any of the properties, which will instead be <code>null</code>. Also note that if any property is ever unavailable (because the Second Life servers did not send it as part of the request), the corresponding property will be <code>null</code>.</p>

	<p>Objects of this class are <em>safe to copy</em> (that is, you can choose to clone an object of this class, using the PHP 4 assignment operator or PHP 5 <code>clone</code> keyword, or pass it by value rather than by reference, without any problem whatsoever).</p>

	<h3 id="properties">Properties</h3>

	<h4 id="comingfromsl">ComingFromSL</h4>

	<pre><code>boolean $ComingFromSL;

	<p>This property is <code>true</code> if the request is coming from Second Life, <code>false</code> otherwise. Other properties are non-<code>null</code> only if this property is <code>true</code>.</p>

	<h4 id="shard">Shard</h4>

	<pre><code>string $Shard;

	<p>The name of the shard the request comes from. Currently it is either <code>"Production"</code> for the main grid or <code>"Testing"</code> for other grids (such as the pubicly accessible beta grid).</p>

	<h4 id="objectnameandobjectkey">ObjectName and ObjectKey</h4>

	<pre><code>string $ObjectName;
	string $ObjectKey;

	<p>The user-visible name and the GUID assigned to the object whose script is making the request.</p>

	<h4 id="regionandregionname">Region and RegionName</h4>

	<pre><code>string $Region;
	string $RegionName;

	<p><code>Region</code> contains the name and absolute position within the region the request is being made from. <code>RegionName</code> only contains the region name for the region and can be used along with <a href="#localposition">LocalPosition</a> to construct a current position or <code>secondlife://</code> URL.</p>

	<h4 id="localpositionlocalrotationandlocalvelocity">LocalPosition, LocalRotation and LocalVelocity</h4>

	<p><a name="localposition"></a></p>

	<pre><code>array $LocalPosition;
	array $LocalRotation;
	array $LocalVelocity;

	<p><code>LocalPosition</code> and <code>LocalVelocity</code> contain a 3D vector in the form of a three-element array; the three elements at keys <code>'x'</code>, <code>'y'</code> and <code>'z'</code> are the three components of the vector in 3D space.</p>

	<p><code>LocalRotation</code> is similar, but it contains a <a href="http://www.lslwiki.net/lslwiki/wakka.php?wakka=quaternions">quaternion</a> encoded as a four-element array with elements at keys <code>'x'</code>, <code>'y'</code>, <code>'z'</code> and <code>'w'</code>.</p>

	<h4 id="ownernameandownerkey">OwnerName and OwnerKey</h4>

	<pre><code>string $OwnerName;
	string $OwnerKey;

	<p><code>OwnerName</code> contains the Second Life first and last names of the owner of the object making the request. <code>OwnerKey</code> contains the GUID associated with that character.</p>

	<h2 id="exampleofuse">Example of use</h2>

	<p>The following example echoes the name of the owner of the object doing the current request, if available:</p>

	    require_once 'CSecondLife.php';
	    header('Content-Type: text/plain');

	    $sl = &amp;new CSecondLife();
	    if ($sl-&gt;ComingFromSL &amp;&amp; !is_null($sl-&gt;OwnerName))
	        echo "Coming from SL Resident {$sl-&gt;OwnerName}";
	        echo "Not coming from SL or Resident unknown!"

	<h2 id="coreintegration">Core integration</h2>

	<p><a href="http://core.infinite-labs.ne">Core</a> is an as-of-yet unreleased PHP micro-framework that helps in creating mid-sized PHP applications with a minimum of effort.</p>

	<p><code>CSecondLife</code> integrates with Core&#8217;s Application Kit. If a Core application imports <code>CSecondLife.php</code>, the <code>CSecondLife</code> is added as an helper object accessible to a running <code>CApp</code> as <code>$this-&gt;SL</code>. For example, you can use <code>$this-&gt;SL-&gt;OwnerKey</code> rather than constructing a <code>CSecondLife</code> object of your own and reading its <code>OwnerKey</code> property.</p>

	<p>If you don&#8217;t develop applications with Core, the class does not depend on the framework and can be used on its own.</p>

Return current item: CSecondLife