View Single Post
Old 01-02-2008, 12:06 AM   #13 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I've had a stab at it as well. Call it the official TalkPHP Bug Me Not Killer! With added cyanide !

php Code:
<?php

    class TalkPHP_BugMeNotKiller
    {
        private $m_szAddress;
       
        private $m_aUsernames;
        private $m_aPasswords;
       
        public function __construct($szAddress)
        {
            $this->m_aUsernames = array();
            $this->m_aPasswords = array();
           
            $this->m_szAddress = sprintf('http://www.bugmenot.com/view/%s', $szAddress);
        }
       
        public function execute()
        {
            $pCurl = curl_init($this->m_szAddress);
           
            curl_setopt($pCurl, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($pCurl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($pCurl, CURLOPT_USERAGENT, 'TalkPHP.com BugMeNot Killer');
           
            $aData = curl_exec($pCurl);
           
            preg_match_all('~<tr><th>.+?\s?</th><td>(?P<username>.+?)</td></tr>\n\s*<tr><th>.+?\s?</th><td>(?P<password>.+?)</td></tr>~im', $aData, $aMatches);
           
            foreach($aMatches['username'] as $szUsername)
            {
                $this->m_aUsernames[] = $szUsername;
            }
               
            foreach($aMatches['password'] as $szPassword)
            {
                $this->m_aPasswords[] = $szPassword;
            }
           
            return $this;
        }
       
        public function hasAccounts()
        {
            if(empty($this->m_aUsernames))
            {
                return false;
            }
           
            return true;
        }
       
        public function getUsernames()
        {
            return $this->m_aUsernames;
        }
       
        public function getPasswords()
        {
            return $this->m_aPasswords;
        }
    }
   
    $pBug = new TalkPHP_BugMeNotKiller('sitepoint.com');
    $pBug->execute();
   
    if($pBug->hasAccounts())
    {
        echo 'Usernames: ' . implode(', ', $pBug->getUsernames());
        echo '<br />';
        echo 'Passwords: ' . implode(', ', $pBug->getPasswords());
    }

?>
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote