PHP Tutorials

XMLStyleSoldierFlowerMonkey

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.

Spreadshirt
On our new hosting site, SpoonoHost, uses a PHP script to detect if the AOL screenname "SpoonoSupport" is currently online to offer Instant Messenger Support through AIM. The code works simply by connecting the AOL IM server, querying it for the screenname, getting a response, and interpreting it.

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";
}
?>


Discuss this tutorial »
Written by: Akash Goel
Back to PHP TutorialsTop


Copyright © 2000-2010 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.

kdfj