<?php
// Auto-add all your Twitter followers as your friends by parsing the followers XML file
// erica douglass, 3/2007

//prompt for user/pass

if (!isset($_SERVER['PHP_AUTH_USER'])) {
    
header('WWW-Authenticate: Basic realm="Enter your Twitter username and password:"');
    
header('HTTP/1.0 401 Unauthorized');
    echo 
'Please enter your Twitter username and password to view your followers.';
    exit();
}

$username $_SERVER['PHP_AUTH_USER'];
$password $_SERVER['PHP_AUTH_PW'];

require(
'xmlparser.php');

$p =& new xmlParser();
$p->parse("http://$username:$password@twitter.com/statuses/followers.xml");
$count 0;
?>

<html>
<body>
<p>This is the proof-of-concept Twitter XML API script as shown on SlashChick.com.</p>
<table border="1">
  <tr>
    <td colspan="2"><?=$username?>'s followers ("Add as a friend" doesn't work because Twitter won't accept direct input of URLs)</td>
  </tr>
<?php
foreach ($p->output[0][child] as $value) {
    
#echo '<pre>';
    #print_r($value);
    #echo '</pre>';
    // each iteration is 1 of my followers
?>
  <tr>
    <td><?=$value[child][2][content]?></td>
    <td><a href="http://twitter.com/friendships/create/<?=$value[child][0][content];?>">Add as a friend</a></td>
  </tr>
<?php
     
#print $value[child][0][content]; // ID
     #print $value[child][2][content]; // SN
    
$count++;
}
?>
</table>
</body>
</html>