User:Ugleh Ulrik/Name2Key

From Second Life Wiki
Jump to navigation Jump to search

This PHP Code will search Second Lifes database and bring back the persons Key This script uses Curl to grab the data because ive tested and Curl goes much faster.

<?php
$p = $_GET['q'];
$user = implode("+", explode(' ', $p));
$url = "http://search.secondlife.com/web/search/?q=$user";
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE ); // return into a variable
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec( $ch ); // run!
curl_close($ch);

$newlines = array(">", "<", "/", "=", "\n");
$content = str_replace($newlines, "", html_entity_decode($result));
$content = stripslashes(preg_replace('/\s\s+/', '', $content));
$html = '/world.secondlife.comresident(.+?)ah/';
preg_match($html,$content,$raw);
$example = $raw[1];
$key = split('"', $example);
echo $key[0];
?>

Upload this PHP file and then go to the url with a GET of q=User Name