I am making an MSN client in PHP. I have this code that connects to the server and goes into MSN:
$server2 = explode(":", $xfr[3]);
$socket2 = pfsockopen($server2[0], (int)$server2[1]);
$_SESSION["socket"] = $socket;
echo '<b>Connected to 2nd server.</b><br />';
fputs($socket2, "VER 0 MSNP10 CVR0\r\n");
echo fread($socket2, 5000) . '<br />';
fputs($socket2, "CVR 1 0x0409 php ".phpversion()." i386 MSNMSGR 7.0.0000 MSMSGS ".$_POST["username"]."\r\n");
echo fread($socket2, 5000) . '<br />';
fputs($socket2, "USR 2 TWN I ".$_POST["username"]."\r\n");
$usr = fread($socket2, 5000);
echo $usr . '<br />';
$usr = explode(" ", $usr);
Now I need to use this socket on another page ( AJAX/status.php). php.net says the connection remains available. However, this is status.php (just ignore $ _SESSION ["cid"]), which is called via AJAX:
<?php
session_start();
fputs($_SESSION["socket"], "CHG 12 " . $_GET["s"] . " " . $_SESSION["cid"], 5000);
echo fread($_SESSION["socket"]);
What should change the status. I get this error:
<br />
<b>Warning</b>: fputs(): supplied argument is not a valid stream resource in <b>C:\wamp\apps\msnphp\AJAX\status.php</b> on line <b>3</b><br />
<br />
<b>Warning</b>: Wrong parameter count for fread() in <b>C:\wamp\apps\msnphp\AJAX\status.php</b> on line <b>4</b><br />
My socket is persistent and its identifier is stored in the session variable $ _SESSION ["socket"]. I do not understand why this does not work.
I am using Windows XP Professional SP2 as a server, with a WAMP server (Apache, MySQL and PHP).
Can anyone help me? Thanks!
user142019