Adding YM online status icons to websites using PHP and HTML scripts

2009 Jul 7

Adding Yahoo Messenger status icons to websites is fairly easy and straightforward, it doesn't even need any programming language to customize them. By this time, i have gathered 25 different status messages that can be used to display while the user is online or offline on Yahoo Messenger.

Using OPI from yahoo, we will be able to detect whether a user is online. For example my Yahoo Id is 'tildemark', use the following address to know if i am online on Yahoo Messenger: http://opi.yahoo.com/online?u=tildemark 

obviously the query string u=tells OPI to check for any user having a Yahoo Id of tildemark. The script then returns a status graphics "online" and "not online".

To add this on any website, we therefore use the syntax:  (you will need to replace YahooID with your corresponding ID)

<img src="http://opi.yahoo.com/online?u=YahooID" />

The code above will display a cute smiley face icon if your online and a gray icon if your offline. Below is a table of the 25 possible icons to customize your Yahoo Messenger online status.


Style # Online Status Offline Status Dimension
0 onlinet0 offlinet0  
1 onlinet1 offlinet1  
2 onlinet2 offlinet2  
3 onlinet3 offlinet3  
4 onlinet4 offlinet4  
5 onlinet5 offlinet5  
6 onlinet6 offlinet6  
7 onlinet7 offlinet7  
8 onlinet8 offlinet8  
9 onlinet9 offlinet9  
10 onlinet10 offlinet10  
11 onlinet11 offlinet11  
12 onlinet12 offlinet12  
13 onlinet13 offlinet13  
14 onlinet14 offlinet14  
15 onlinet15 offlinet15  
16 onlinet16 offlinet16  
17 onlinet17 offlinet17  
18 onlinet18 offlinet18  
19 onlinet19 offlinet19  
20 onlinet20 offlinet20  
21 onlinet21 offlinet21  
22 onlinet22 offlinet22  
23 onlinet23 offlinet23  
24 onlinet24 offlinet24  

 

To display an icon with the style number 2, we use this syntax in HTML:

<img src="http://opi.yahoo.com/online?u=YahooID&t=2" border="0" />

 

You can also add a custom message when a user clicks on the image to launch Yahoo Messenger and start a chat with the default message as "hello":

<a href="ymsgr:sendIM?YahooID&m=Hello"><img src="http://opi.yahoo.com/online?u=YahooID&t=StyleID" border="0">a>

 

What if we would like to create our own status image? Using the code above, there will be no way we could that without the use of a programming language.  Another helpful option to our query string allows us to choose to display graphics or by a mere status message saying "ONLINE" and "NOT ONLINE" using 'm'. Adding that option to our query string we get:

<img src="http://opi.yahoo.com/online?u=YahooID&m=g&t=StyleID" border="0">

I don't know what 'm' stands for but im guessing its 'mode' and 'g' means 'graphics'. Nothing will happen to our status message until we set 'm' to 'a'.

<img src="http://opi.yahoo.com/online?u=YahooID&m=a&t=StyleID" border="0">

Since we need to compare things we will set 'm' to 'a' because it will be hard to compare things in graphics, although its possible but comparing string is way easier.

Furthermore, notice that when using 'm=a' and setting 't=0' gives us the text status and setting 'm=a' and 't=1' gives us a numeric status. Things got more easier for us now. whenever the status returns '00' it means the YahooID is offline, and its '01' the YahooID is online.

Here is a PHP class for yahoo status, we will just add more features to it while we progress but for now it will just check for online status.


                    
  1: php

                    
  2: /**

                    
  3:  * @version 1

                    
  4:  * @package Miscelaneous

                    
  5:  *  Copyright (C) 2009 tildemark.com. All rights reserved.

                    
  6:  * @license GNU/GPL

                    
  7:  * @author tildemark

                    
  8:  */

                    
  9: 

                    
 10: class Yahoo {

                    
 11:   function Get_status($yahooid){

                    
 12:     $status = file_get_contents("http://opi.yahoo.com/online?u=$yahooid&m=a&t=1");

                    
 13:     if ($status === '00')

                    
 14:       return false;

                    
 15:     elseif ($status === '01')

                    
 16:       return true;

                    
 17:   }

                    
 18: }

                    
 19: 

                    

 

Save it as class.yahoo.php. To test the code we write the following:


                    
  1: php

                    
  2: // create a new instance of the class

                    
  3: $ys = new Yahoo();

                    
  4: 

                    
  5: // assign a temporary id, we will 

                    
  6: //use ernie id because he's always online

                    
  7: $id = 'ernmats';

                    
  8: 

                    
  9: get the online status

                    
 10: $status = $ys->Get_status($id);

                    
 11: if ($status == false)

                    
 12:   echo "offline";

                    
 13: elseif($status == true)

                    
 14:   echo "online";

                    
 15: ?>

                    

 

I have attached the Yahoo Status Class source code here if you do like to manually encode them.

Tweet this post

Related Entries

Leave a comment


Recent Entries

Close