Difference between revisions of "User:Jor3l Boa/PHP/n2k.php"
Qwerty Venom (talk | contribs) |
|||
Line 42: | Line 42: | ||
$data = getPage($SL_SEARCH.$sName[0].'%2520'.$sName[1]); | $data = getPage($SL_SEARCH.$sName[0].'%2520'.$sName[1]); | ||
$uuid = getBetween($data,'secondlife:///app/agent/','/about'); | $uuid = getBetween($data,'secondlife:///app/agent/','/about'); | ||
if(!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/",$uuid)) $uuid = '00000000-0000-0000-0000-000000000000'; | |||
return $uuid; | |||
} | |||
?> | |||
</php> | |||
Updated version of n2k.php that will work with the new design | |||
<php> | |||
<?php | |||
// PHP name2Key by Jor3l Boa | |||
// Updated by Qwerty Venom | |||
// ------------------------- | |||
// Released under Creative Commons 3.0 | |||
// - devi@foravatars.com | |||
// ------------------------- | |||
// Updated: 08/12/2010 | |||
function getPage($web) { | |||
$html = ""; | |||
$ch = curl_init($web); | |||
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12"); | |||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |||
curl_setopt($ch, CURLOPT_HEADER, 0); | |||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |||
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); | |||
curl_setopt($ch, CURLOPT_TIMEOUT, 5); | |||
$html = curl_exec($ch); | |||
if(curl_errno($ch)) { | |||
$html = ""; | |||
} | |||
curl_close ($ch); | |||
return $html; | |||
} | |||
function getBetween($content,$start,$end){ | |||
//by Jor3l :) | |||
$a1 = strrpos($content,$start); | |||
$content = substr($content,$a1 + strlen($start)); | |||
while($a2 = strrpos($content,$end)) { | |||
$content = substr($content,0,$a2); | |||
} | |||
return $content; | |||
} | |||
function name2Key($name) { | |||
$SL_SEARCH = 'http://search.secondlife.com/web/search/people/?q='; | |||
$sName = split(' ',$name); | |||
$data = getPage($SL_SEARCH.$sName[0].'+'.$sName[1]); | |||
$uuid = getBetween($data,'http://world.secondlife.com/resident/','" class="profile_link"'); | |||
if(!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/",$uuid)) $uuid = '00000000-0000-0000-0000-000000000000'; | if(!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/",$uuid)) $uuid = '00000000-0000-0000-0000-000000000000'; | ||
return $uuid; | return $uuid; |
Revision as of 15:30, 11 August 2010
PHP Based name2Key service.
n2k.php: <php> <?php // PHP name2Key by Jor3l Boa // ------------------------- // Released under Creative Commons 3.0 // - devi@foravatars.com // ------------------------- // Updated: 5/04/2010
function getPage($web) {
$html = ""; $ch = curl_init($web); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $html = curl_exec($ch); if(curl_errno($ch)) { $html = ""; } curl_close ($ch); return $html; }
function getBetween($content,$start,$end){
//by Jor3l :) $a1 = strrpos($content,$start); $content = substr($content,$a1 + strlen($start)); while($a2 = strrpos($content,$end)) { $content = substr($content,0,$a2); } return $content; }
function name2Key($name) { $SL_SEARCH = 'http://search.secondlife.com/client_search.php?session=00000000-0000-0000-0000-000000000000&q='; $sName = split(' ',$name); $data = getPage($SL_SEARCH.$sName[0].'%2520'.$sName[1]); $uuid = getBetween($data,'secondlife:///app/agent/','/about');
if(!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/",$uuid)) $uuid = '00000000-0000-0000-0000-000000000000';
return $uuid; } ?> </php>
Updated version of n2k.php that will work with the new design <php> <?php // PHP name2Key by Jor3l Boa // Updated by Qwerty Venom // ------------------------- // Released under Creative Commons 3.0 // - devi@foravatars.com // ------------------------- // Updated: 08/12/2010
function getPage($web) {
$html = ""; $ch = curl_init($web); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $html = curl_exec($ch); if(curl_errno($ch)) { $html = ""; } curl_close ($ch); return $html; }
function getBetween($content,$start,$end){
//by Jor3l :) $a1 = strrpos($content,$start); $content = substr($content,$a1 + strlen($start)); while($a2 = strrpos($content,$end)) { $content = substr($content,0,$a2); } return $content; }
function name2Key($name) { $SL_SEARCH = 'http://search.secondlife.com/web/search/people/?q='; $sName = split(' ',$name); $data = getPage($SL_SEARCH.$sName[0].'+'.$sName[1]); $uuid = getBetween($data,'http://world.secondlife.com/resident/','" class="profile_link"');
if(!preg_match("/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/",$uuid)) $uuid = '00000000-0000-0000-0000-000000000000';
return $uuid; } ?> </php>
example: <php> <? require_once('n2k.php'); $uuid = name2key('FirstName LastName'); echo $uuid; ?> </php>
NOTE ON HOSTING PROVIDERS:
Some hosting providers, notably GoDaddy, do not allow outbound traffic from their servers. If you find that this script returns nothing, no matter what you try, that may be your issue. The only fix is to switch providers to one that does allow outbound traffic.
For an LSL version, see also: Name2Key_in_LSL