Forum RSS Scraper

From libsecondlife

Jump to: navigation, search

Here's a nice little PHP script that will re-publish the RSS feed for the Second Life forums that is usually inaccessible to aggregators like Google homepage.

<?php
//Please note that curl proxy support was used to get around OpenSSL limitations of my
// webhost, you probably will not need those (or will need to adjust them to your settings)
// I commented them out for now
$username = "Firstname"; 
$lastname = "Lastname";
$password = "pass"; 
$cookiefile = "cookie";

//Second Life servers report context as
//  Content-Type: text/xml;charset=utf-8
//  Content-Language: en
//So do likewise
header("Content-Type: text/xml;charset=utf-8"); 
header("Content-Language: en"); 

//clear cookies if they exist
if(file_exists($cookiefile))
  `rm $cookiefile`;

$postfields="form[type]=second-life-member";
//$postfields.="&form[nextpage]=/account/index.php"; //what it is normally set to on login
$postfields.="&form[nextpage]=http://forums.secondlife.com/external.php?type=RSS2";
$postfields.="&form[persistent]=Y";
$postfields.="&form[username]=$username";
$postfields.="&form[lastname]=$lastname";
$postfields.="&form[password]=$password";
$postfields.="&submit=Submit";

//init curl and setup options
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://secure-web0.secondlife.com/account/login.php"); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields"); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 

//crap GoDaddy requires to get https to work with libcurl ssl
//curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
//curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");

curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 20); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); 

//for debugging, set true
curl_setopt ($ch, CURLOPT_HEADER, FALSE); 
curl_setopt ($ch, CURLOPT_VERBOSE, FALSE); 
//curl_setopt ($ch, CURLOPT_HEADER, TRUE); 
//curl_setopt ($ch, CURLOPT_VERBOSE, TRUE); 

curl_exec($ch); 
curl_close($ch); 
unset($ch); 

?>