Jump to content

[SOLVED] Help getting remote data...


bzz

Recommended Posts

OK. AOL has a website that lets you 'query the status' of an AOL/AIM user:

 

http://api.oscar.aol.com/presence/icon?k=ll1UnrcbSft40WZH&t=*USER_NAME*

 

The problem is that this website returns a .gif image based upon the user's status.. so if they're offline it will return:

 

http://o.aolcdn.com/aim/img/offline.gif

 

and online:

 

http://o.aolcdn.com/aim/img/online.gif

 

etc.. the problem is it doesn't send the text for this, it returns the actual image.. so what I did to work around it was pre-calculated the md5 of each image and set those as constants, then used the file_get_contents() function to return the contents of the website (ascii of the .gif) and calculate the md5 then compare it to the list of precalculated hashes.... there has to be a better way of doing this.. maybe finding out the url of the image and remove everything from the last / to the .gif ?

 

Help!! (I can post my current code if necessary or if anybody is interested)

 

Here are a few screen names to test out:

 

http://api.oscar.aol.com/presence/icon?k=ll1UnrcbSft40WZH&t=ninja

 

http://api.oscar.aol.com/presence/icon?k=ll1UnrcbSft40WZH&t=bzz

 

http://api.oscar.aol.com/presence/icon?k=ll1UnrcbSft40WZH&t=xua

 

http://api.oscar.aol.com/presence/icon?k=ll1UnrcbSft40WZH&t=llh

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/134601-solved-help-getting-remote-data/
Share on other sites

It's sending back a 302 header, so you need to use something lower level than file_get_contents so you can capture that.

 

 

For example (no error checking because I'm lazy):

 

<?php
$s = fsockopen('api.oscar.aol.com', 80);
fwrite($s, "GET /presence/icon?k=ll1UnrcbSft40WZH&t=ninja HTTP/1.1\nHost: api.oscar.aol.com\nConnection: close;\n\n");
while(!feof($s)) {
    $line = fgets($s);
    if(stripos($line, "Location:") === 0) {
        if(stripos($line, "online") !== false) {
            //online
        }
        elseif(stripos($line, "offline") !== false) {
            //offline
        }
        else {
            //unknown
        }
        break;
    } 
}
fclose($s);

<?php
$h = curl_init('http://api.oscar.aol.com/presence/icon?k=ll1UnrcbSft40WZH&t=USERNAME');
curl_setopt($h, CURLOPT_HEADER, true);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($h);
preg_match('%Location:.*(online|offline).gif%', $output, $matches);
echo $matches[1]; // contains the string "offline" or "online" depending on the user
?>

 

there might be an even simpler way. Perhaps instead of using regex you could just use a strpos() for online (which is faster than regex) and if it does not find it, you can just assume the user is offline.

 

Added after I see that corbin posted: looks like he used strpos() :) but in all fairness I'll leave my slower alternative above.

It's working, thanks!

 

I was originally looking to do it using fsockopen, but I stopped for some reason (don't remember why) and just used whatever I could get working.

 

It's also a heck of a lot faster, since it's not calculating the md5 of several different gif images  ::)

 

Here's the final function if anybody's interested. (The key variable comes from the AIM dev site [ api.oscar.aol.com ], you can register to get your own from there, just need a valid AIM/AOL screen name)

 

<?php
function get_aim_status($sn) {
$key = "ll1UnrcbSft40WZH";
$s = fsockopen('api.oscar.aol.com', 80);
fwrite($s, "GET /presence/icon?k=$key&t=$sn HTTP/1.1\nHost: api.oscar.aol.com\nConnection: close;\n\n");
while(!feof($s)) {
    $line = fgets($s);
    if(stripos($line, "Location:") === 0) {
        if(stripos($line, "online.") !== false) {
                return 'Online';
        }
        elseif(stripos($line, "offline.") !== false) {
                return 'Offline';
        }
        elseif(stripos($line, "away.") !== false) {
                return 'Away';
        }
        elseif(stripos($line, "mobile.") !== false) {
                return 'Mobile';
        }
        elseif(stripos($line, "idle.") !== false) {
                return 'Idle';
        }
else {
                return 'Unknown';
        }
                break;
        }
     }
fclose($s);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.