The CSecondLife class

CSecondLife is a class that extracts information from HTTP requests that originate from Second Life objects. Through HTTP, you can have a Second Life object interact with a PHP backend to create complex in-world applications.

For more information about making HTTP requests from within Second Life, see the documentation at the LSL Wiki for the llHTTPRequest function.



new CSecondLife();

The constructor initializes the CSecondLife instance’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 null. 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 null.

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



boolean $ComingFromSL;

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


string $Shard;

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

ObjectName and ObjectKey

string $ObjectName;
	string $ObjectKey;

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

Region and RegionName

string $Region;
	string $RegionName;

Region contains the name and absolute position within the region the request is being made from. RegionName only contains the region name for the region and can be used along with LocalPosition to construct a current position or secondlife:// URL.

LocalPosition, LocalRotation and LocalVelocity

array $LocalPosition;
	array $LocalRotation;
	array $LocalVelocity;

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

LocalRotation is similar, but it contains a quaternion encoded as a four-element array with elements at keys 'x', 'y', 'z' and 'w'.

OwnerName and OwnerKey

string $OwnerName;
	string $OwnerKey;

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

Example of use

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

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

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

Core integration

Core is an as-of-yet unreleased PHP micro-framework that helps in creating mid-sized PHP applications with a minimum of effort.

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

If you don’t develop applications with Core, the class does not depend on the framework and can be used on its own.