Articles: 843 | Categories: 148   
   
   
Home Articles Contact Us
 
 
 
 
AOL IM Check User Online (0 Comments)
Admin: Posted Date: April 4, 2010

Learn to see see if a user is currently online on AOL Instant Messenger using PHP. The tutorial uses PHP functions including sockets, files, and strings.

AOL IM Check User Online

Learn to see see if a user is currently online on AOL Instant Messenger using PHP. The tutorial uses PHP functions including sockets, files, and strings.

We're first going to start off by opening a socket connection to the AOL server using the fsockopen function.

<?
// Connect to AOL server
$url = @fsockopen("big.oscar.aol.com", 80, &$errno, &$errstr, 3);
Now, we want to query the server for the username "SpoonoSupport":
// Query the Server
fputs($url, "GET /spoonosupport?on_url=online&off_url=offline HTTP/1.0\n\n");
Now that we have the information, we need to get the resultant page and then close the connection. To make sure there is not a time out, if the process takes more than 10 passes, it will assume the screenname is offline:
// See resultant page
while(!feof($url)){
$feofi++;
$page .= fread($url,256);
if($feofi > 10){
$page = "offline";
break;
}
}
fclose($url);
The reply from the server (unless it times out) is either one of these two:
HTTP/1.1 302 Redirection Location: online IMG src=online
HTTP/1.1 302 Redirection Location: online IMG src=offline

Obviously, if it's the first one, then the screenname is online, if the latter, than the screenname is offline. To have our code detect that, we will use the strstr(), and find the first instance of the term "online". If the term is found, then we can assume the user is online. If not, than the user is offline:

// determine online status 
if(strstr($page, "online")){
echo "the user is online";
}else{
echo "the user is offline";
}
?>
The final code, all compiled together:
<?
// Connect to AOL server
$url = @fsockopen("big.oscar.aol.com", 80, &$errno, &$errstr, 3);
// Query the Server
fputs($url, "GET /spoonosupport?on_url=online&off_url=offline HTTP/1.0\n\n");
// See resultant page
while(!feof($url)){
$feofi++;
$page .= fread($url,256);
if($feofi > 10){
$page = "offline";
break;
}
}
fclose($url);
// determine online status 
if(strstr($page, "online")){
echo "the user is online";
}else{
echo "the user is offline";
}
?>

 

 

 

 
 
Add a Comment:
 
(You must be signed in to comment on an article. Not a member? Click here to register)
   
Title:

Comments: