Web login code/php5

From Second Life Wiki
Revision as of 12:55, 8 January 2008 by SignpostMarv Martin (talk | contribs) (added PHP5 Version)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is an implementation of the Python script in PHP5

The script requires PHP 5.1.3 or later.

<php># Created by SignpostMarv Martin

  1. Based on https://wiki.secondlife.com/wiki/Web_login_code/python

class sl_web_login { const regex_web_login_key = '/web_login_key=([0-9a-f]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})/'; const regex_Resident_uuid = '/second-life-member=([0-9a-f]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})/'; const NULL_KEY = '00000000-0000-0000-0000-000000000000'; public function __construct($first,$last,$password,$location='home',$grid='agni',$continuation=) { $ch = curl_init('https://secure-web14.secondlife.com/app/login/go.php'); if($ch === false) { throw new Exception('Couldn\'t initialise a cURL handle',100); } curl_setopt_array($ch, array( CURLOPT_POST => 1, CURLOPT_HEADER => 1, CURLOPT_FOLLOWLOCATION => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPHEADER => array( 'Accept:text/plain', ), CURLOPT_POSTFIELDS => array( 'username' => $first, 'lastname' => $last, 'password' => $password, 'continuation' => $continuation, 'grid' => $grid, 'location' => $location, ), ) ); $this->data = curl_exec($ch); $this->info = curl_getinfo($ch); if($this->data === false) { $this->error = curl_error($ch); $this->web_login_key = sl_login::NULL_KEY; $this->uuid = sl_login::NULL_KEY; } else { if(preg_match(sl_login::regex_web_login_key,$this->data,$matches)) { $this->web_login_key = $matches[1]; } else { throw new Exception('Could not locate web login key',101); } if(preg_match(sl_login::regex_Resident_uuid,$this->data,$matches)) { $this->uuid = $matches[1]; } else { throw new Exception('Could not locate Resident UUID',102); } } curl_close($ch); } }</php>