Solved

PHP and Yahoo! Messenger

Posted on 2006-11-05
21
2,103 Views
Last Modified: 2012-05-05
Dear Experts,

I have been looking for so long without catching the solution. Is it possible to connect to Yahoo! Messenger server using PHP socket? If not, how about other messengers like Windows Live Messenger?
0
Comment
Question by:nktpro
  • 10
  • 8
  • 2
  • +1
21 Comments
 
LVL 16

Accepted Solution

by:
ellandrd earned 500 total points
ID: 17876854
0
 

Author Comment

by:nktpro
ID: 17876876
Thank you so much Ellandrd! How about Yahoo! Messenger? Anybody can help me to find a similar PHP class for Y!M? I am really looking forward to get it. Thank you!
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17876904
i have never found 1 yet so i dont think there is any PHP classes available. sorry
0
 
LVL 16

Assisted Solution

by:ellandrd
ellandrd earned 500 total points
ID: 17876934
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 17879842
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17879864
nice call mate!
0
 

Author Comment

by:nktpro
ID: 17880198
That class from phpclasses.org I have checked so far, but actually this PHP class make a connection to another middle-man-website like Meebo, and grab the data there. It is not the direct connection to the Yahoo! Messenger server. :((. If this problem can be solve, we can develop the customer support system or a notification system for the webmaster once the customers contact him through the web-based form, he will be notified immediately through Y!M.
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17880223
i was quite surprised to see that my pal, aamir found these classes.  i didnt know they existed. i havent looked at them either yet so im not sure if you can just connect directly with the M-I-M helper...

what is it that your trying to develop exactly?
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 17880802
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17880813
all the points to aamir - he's on fire today!

ellandrd
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:nktpro
ID: 17881112
This is what the class that aamir has found does. Let's have a look at the code:

function login($user,$pass){
      
      $server="lima";
      $data="";
      $content="messengerType=yahoo&username=$user&=&password=$pass&inv=off";
      $length=strlen($content);
      $data.="POST /webyahoo/doLogin.jsp HTTP/1.1\n";
      $data.="Accept: */*\n";
      $data.="Referer: http://e-messenger.net/\n";
      $data.="Accept-Language: fa\n";
      $data.="Content-Type: application/x-www-form-urlencoded\n";
      $data.="Accept-Encoding: gzip, deflate\n";
            $data.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Avant Browser [avantbrowser.com]; .NET CLR 1.1.4322)\n";
      $data.="Host: $server.e-messenger.net\n";
      $data.="Content-Length: $length\n";
      $data.="Connection: Keep-Alive\n";
      $data.="Cache-Control: no-cache\n";
      $data.="Cookie: user_name=$user; $phpcookie\n\n";
      $data.=$content;
      $fp = @fsockopen ("$server.e-messenger.net", 80, $errno, $errstr, 100);
      if(!$fp){echo "can not connect to $server.e-messenger.net";exit;}
      @fputs ($fp, $data);
      $str="";
      while (!feof($fp)){
            $str.= fgets ($fp,128);
            if(strpos($str,'Path=/webyahoo')){break;}
      }
      @fclose ($fp);
      $jspcookie=trim(yim_getbet('JSESSIONID=',';',$str));

      $data="";
      $data.="GET /webyahoo/signing.jsp HTTP/1.1\n";
      $data.="Accept: */*\n";
      $data.="Referer: http://e-messenger.net/\n";
      $data.="Accept-Language: fa\n";
      $data.="Accept-Encoding: gzip, deflate\n";
            $data.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Avant Browser [avantbrowser.com]; .NET CLR 1.1.4322)\n";
      $data.="Host: $server.e-messenger.net\n";
      $data.="Connection: Keep-Alive\n";
      $data.="Cache-Control: no-cache\n";
      $data.="Cookie: user_name=$user; JSESSIONID=$jspcookie; $phpcookie\n\n";
      $fp = @fsockopen ("$server.e-messenger.net", 80, $errno, $errstr, 100);
      if(!$fp){echo "can not connect to $server.e-messenger.net";exit;}
      @fputs ($fp, $data);
      @fclose ($fp);

      $data="";
      $data.="GET /webyahoo/main.jsp HTTP/1.1\n";
      $data.="Accept: */*\n";
      $data.="Referer: http://e-messenger.net/\n";
      $data.="Accept-Language: fa\n";
      $data.="Accept-Encoding: gzip, deflate\n";
            $data.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Avant Browser [avantbrowser.com]; .NET CLR 1.1.4322)\n";
      $data.="Host: $server.e-messenger.net\n";
      $data.="Connection: Keep-Alive\n";
      $data.="Cache-Control: no-cache\n";
      $data.="Cookie: user_name=$user; JSESSIONID=$jspcookie; $phpcookie\n\n";
      $fp = @fsockopen ("$server.e-messenger.net", 80, $errno, $errstr, 100);
      if(!$fp){echo "can not connect to $server.e-messenger.net";exit;}
      @fputs ($fp, $data);
      @fclose ($fp);
      $cookie="user_name=$user; JSESSIONID=$jspcookie; $phpcookie";
      //$r=array();
      //$r["cookie"]=$cookie;
      //$r["server"]=$server;
      return $cookie;      
}

e-messenger.net is actually a system using JSP to connect to Y!M server as a client, and re-provide this service to users through web-based. That means this class can only connect to that middle-man through HTTP and grab the data back. What we need is exactly another e-messenger.net written in PHP. Anyway thank you very much aamir!
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17881178
again - like i said - im doubtful if it can be done, but you never answered my question above.  here it is again:

what is it that your trying to develop exactly?

ellandrd
0
 

Author Comment

by:nktpro
ID: 17881805
There are a few things can be done:
- To make a web-based Y!M client for users like meebo, e-messenger using PHP, not JSP.
- To improve the customer support system. For ex.: Some customers contact you through a form in a website, immediately you will receive the message through Y!M from a built-in nickname. Moreover, you can instantly chat with this customer! (He is using the form in your website, you are using Y!M, the two are connected with each other thanks to a PHP app in your server. He doesn't need to have a Y!M nickname and login to Y!M client software, as for you nickname, add you as friend etc., you dont need to check email to see his message, of go to your web-based system to chat with him like traditional way)

Because in Asia Y!M is a very popular way to communicate, with the connection to their server using PHP, you can build a lot of cool stuff you can think about just with PHP.
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17881870
Mmm, like i said im doubtful.  i have had a good search around even again today and couldnt find anything like that you want.

however i did find this:

Instant Messenger - Create a service like ICQ on your website.
Create a service like ICQ on your website. The software has basically the same functionality as ICQ, MSN or Yahoo instant messengers. The users can manage contact and ignore lists (that are kept on server), see online status of your contacts and have one-to-one communications. Other features: build-in multi-user live chat, custom smileys, skins. Server-side script is written for PHP/MySQL.

http://www.shareup.com/Instant_Messenger-download-44016.html
0
 

Author Comment

by:nktpro
ID: 17885508
Thanks ellandrd but that one is only a chatting application to integrate into a website. It has no connection with Y!M server :((. I still think it's possible for PHP.
0
 

Author Comment

by:nktpro
ID: 17887563
Good news! After a few days trying to solve this problem, I have found out that I can make it work! The only problem I got stuck and cannot solve myself is the Login Encryption Algorithm. After we send the request to Y!M server using PHP fsockopen, Y!M send back the challenge string. This challenge string must be combined with the username and password to generate a 2 50-characters-strings for authentication. I have found quite a lot of this function but all are in C, VB, Perl of Java version. There is still no similar one for PHP and I really want to make it.

Is there anyone who is familiar with either C, VB, Perl or Java other than PHP can help  me to convert this function to PHP? I will post this function in all available languages for you for reference. I will be really thankful for it!
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17887569
post the java please - i will see what i can do...
0
 

Author Comment

by:nktpro
ID: 17890043
The source code are quite long to post here, I post it to pastebin.ca instead.

http://pastebin.ca/242643  -> ChallengeResponseUtility.java
http://pastebin.ca/242651 -> ChallengeResponseV10.java
http://pastebin.ca/242653 -> ChallengeResponseV10Tables.java

Let me explain a bit what we need:

- First we make the request to Y!M server like this:

0x0000   59 4D 53 47 00 0D 00 00-00 0C 00 57 00 00 00 00   YMSG.......W....
0x0010   00 00 00 00 31 C0 80 70-74 63 6E 6E 6F 6C C0 80   ....1À€ptcnnolÀ€

- The Y!M reply smt like this:

0x0000   59 4D 53 47 00 00 00 00-00 59 00 57 00 00 00 01   YMSG.....Y.W....
0x0010   8A 5C B7 80 31 C0 80 70-74 63 6E 6E 6F 6C C0 80   Š\·€1À€ptcnnolÀ€
0x0020   39 34 C0 80 33 7C 6D 2F-72 2A 78 25 28 79 25 65   94À€3|m/r*x%(y%e
0x0030   2A 70 2D 79 5E 63 2F 79-26 75 2F 78 29 2D 76 7C   *p-y^c/y&u/x)-v|
0x0040   65 7C 6F 5E 35 2D 28 6E-5E 6D 2B 7A 29 26 76 2F   e|o^5-(n^m+z)&v/
0x0050   72 25 35 2B 72 5E 61 2D-28 79 26 74 2B 78 2A 62   r%5+r^a-(y&t+x*b
0x0060   25 6A 29 C0 80 31 33 C0-80 31 C0 80 00                %j)À€13À€1À€.

And the string "3|m/r*x%(y%e*p-y^c/y&u/x)-v|e|o^5-(n^m+z)&v/r%5+r^a-(y&t+x*b%j)" is the challenge.
We need a function like this

yahoo_login($username, $password, $challenge);

to combine the username, password, and the challenge string above, and generate the 2 50-characters-strings for authentication, that will be send back to Y!M server and BINGO, we are already logged in! That's what it will look like:

0x0000   59 4D 53 47 00 0D 00 00-00 BC 00 54 00 00 00 00   YMSG.....¼.T....
0x0010   8A 5C B7 80 36 C0 80 72-3D 6D 36 2C 46 3D 62 34   Š\·€6À€r=m6,F=b4
0x0020   3B 4F 3D 6E 45 3B 52 3D-6C 68 2C 41 3D 6D 30 2C   ;O=nE;R=lh,A=m0,
0x0030   4C 3D 6A 46 2C 43 3D 67-70 3B 77 3D 30 30 2C 4F   L=jF,C=gp;w=00,O
0x0040   3D 39 38 2C 44 3D 70 64-3B C0 80 39 36 C0 80 51   =98,D=pd;À€96À€Q
0x0050   3D 45 36 3B 42 3D 45 68-3B 6B 3D 63 65 2C 4E 3D   =E6;B=Eh;k=ce,N=
0x0060   6A 61 2C 4C 3D 43 38 3B-57 3D 41 6A 3B 43 3D 6B   ja,L=C8;W=Aj;C=k
0x0070   65 2C 4C 3D 64 44 2C 58-3D 35 38 3B 47 3D 46 31   e,L=dD,X=58;G=F1
0x0080   2C C0 80 30 C0 80 70 74-63 6E 6E 6F 6C C0 80 32   ,À€0À€ptcnnolÀ€2
0x0090   C0 80 70 74 63 6E 6E 6F-6C C0 80 31 39 32 C0 80   À€ptcnnolÀ€192À€
0x00A0   2D 31 C0 80 31 C0 80 70-74 63 6E 6E 6F 6C C0 80   -1À€1À€ptcnnolÀ€
0x00B0   31 33 35 C0 80 37 2C 30-2C 30 2C 32 34 32 C0 80   135À€7,0,0,242À€
0x00C0   31 34 38 C0 80 33 30 30-C0 80 35 C0 80 39 C0 80   148À€300À€5À€9À€

The two generated strings are:

r=m6,F=b4;O=nE;R=lh,A=m0,L=jF,C=gp;w=00,O=98,D=pd;      and
Q=E6;B=Eh;k=ce,N=ja,L=C8;W=Aj;C=ke,L=dD,X=58;G=F1,

That's all I need. The rest of the application I can finish with ease once I can login. This sounds quite complicated but the others have done it in C, VB, Java, Perl, but not PHP :((. Can you be the first?


0
 

Author Comment

by:nktpro
ID: 17905355
Ok, after a few day getting stuck, now I've got the solution! Will release the PHP version to community soon :). Thanks for your helps.
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17905599
brillant!

thanks for the points!

ellandrd
0
 

Expert Comment

by:ghostd0g
ID: 22385413
Can you share the code please ?
:)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now