Location: PHPKode > scripts > Send PM with Yahoo messenger from PHP > send-pm-with-yahoo-messenger-from-php/yahoo.class.php
<?
class carcabot {

var $yahoo_id = null;
var $yahoo_password = null;
var $victimid = null;
var $mesaj = null;
var $callback = false;


function carcabot($yahoo_id, $yahoo_password, $victimid, $mesaj) {


$this->yahoo_id = $yahoo_id;
$this->yahoo_password = $yahoo_password;
$this->victimid = $victimid;
$this->mesaj = $mesaj;

$_done = $this->get("http://us.m1.yahoo.com/p/messenger");
$_done = substr($_done, strpos($_done, "_done") + 14);
$_done = substr($_done, 0, strpos($_done, "\""));
$curl_data = $this->post("http://us.m1.yahoo.com/p/login/auth?ignore=signin","_done=" . $_done . "&_pc=&_src=&_ts=&_sig=&_css=&_intl=&_second_user=no&username=" . $yahoo_id . "&password=" . $yahoo_id_password . "&action=Sign+in");
$curl_data = $this->get("http://us.m1.yahoo.com/p/messenger/");
$getagain = $this->get_between($curl_data, "<a href=\"/p/messenger?c","\">");
$getagain = "/p/messenger?c".$getagain;
$post_url = $this->get("http://us.m1.yahoo.com".urldecode($getagain));
$chat = $this->get_between($post_url, "/p/messenger/chat?c", "\"");
$chat = "/p/messenger/chat?c".urldecode($chat);
$chat = $this->get("http://us.m1.yahoo.com". $chat);
$action = $this->get_between($chat, "action=\"/p/messenger/chat/","\">"); // We get action url
$action = '/p/messenger/chat/'.$action;
$post_url = "http://us.m1.yahoo.com" . urldecode($action);

if($this->post($post_url, "user=".$victimid."&message=".$mesaj."&wmlfix=Send")) {
echo "$victimid -> <font color=green>Sent</font><br/>";
flush();
ob_flush();
} else {
echo "$victimid -> <font color=red>Not Sent</font><br/>";
flush();
ob_flush();
}
}

function get_between($content,$start,$end){
        $r = explode($start, $content);
        if (isset($r[1])){
            $r = explode($end, $r[1]);
            return $r[0];
        }
        return '';
    }



function setCallback($func_name) {
    $this->callback = $func_name;
}

function doRequest($method, $url, $vars) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
//    curl_setopt($ch, CURLOPT_PROXY, 'ip:port'); // if you want use proxy just uncomment this
    if ($method == 'POST') {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
    }
    $data = curl_exec($ch);
    curl_close($ch);
    if ($data) {
        if ($callback)
        {
            $callback = $this->callback;
            $this->callback = false;
            return call_user_func($callback, $data);
        } else {
            return $data;
        }
    } else {
        return curl_error($ch);
    }
}

function get($url) {
    return $this->doRequest('GET', $url, 'NULL');
}

function post($url, $vars) {
    return $this->doRequest('POST', $url, $vars);
}
} // end class
?>
Return current item: Send PM with Yahoo messenger from PHP