• Home
  • Posts RSS
  • Comments RSS
  • Edit
  • Adding YM online status icons to websites using PHP and HTML scripts

    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.
    Styles are from numbers 0 - 25.

    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 Copyright (C) 2009 www.tildemark.com. All rights reserved.
    6:  * @license GNU/GPL
    7:  * @author tildemark
    8:  */
    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: }

    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();
    5: // assign a temporary id, we will 
    6: //use ernie id because he's always online
    7: $id = 'ernmats';
    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.

    Thanks to: Tildemark