i have the following code:
<?
//header parser class
require ("parser.php");
global $fp ;
// open a client connection
function conect($host,$port)
{
$fp = fsockopen ($host, $port, $errno, $errstr);
// if a handle is not returned
if (!$fp)
{
return false;
}
else
{
// get the welcome message
$welcome = fgets ($fp, 150);
return true;
}
}
function user($user)
{
// send username and read response
fputs ($fp, "USER $user\n");
$check = fgets($fp, 50);
if (substr($check, 0, 3) == "+OK")
{
return true;
}
else {return false;}
}
function pass ($pass){
// send password and read response
fputs ($fp, "PASS $pass\n");
$ack = fgets($fp, 50);
if (substr($ack, 0, 3) == "+OK")
{
return true;
}
else {return false;}
}
function pop3stat()
{
// send status request and read response
fputs ($fp, "STAT\n");
$status = fgets($fp, 50);
if (substr($status, 0, 3) == "+OK")
{
}
// error getting status
else
{
die ("Server said: $status");
}
// get status string
// split by spaces
$arr = explode(" ", $status);
return $arr;
}
function getmesg($msgnum, $fp)
{
if ($msgnum>=$arr[1])
{
//////send out the retrieve mesage
fputs ($fp, "RETR $msgnum\n");
//initialize the counter
$count = 0;
///create an array for the counter
$MsgArray = array();
//we need to get this value once before the loop
$line = fgets($fp,10000);
//loop while we find /n in $line
while ( !ereg("^\.\r\n",$line))
{
//make the array[0]the first line and then [2] and so on...
$MsgArray[$count] = $line;
// ad one to count
$count++;
//get the next line and loop
$line = fgets($fp,10000);
//if the string is empty contains no new line chars then we break out.
if(empty($line)) { break; }
}
} else {echo "that message does not exist on the server";}
return $MsgArray;
}
// while ( list ( $lineNum,$line ) = each ($cool) )
// {
// echo "$line <BR>\n";
//}
function quit(){
fputs ($fp, "QUIT\n");
fclose ($fp);
}
?>
i use another script to connect to the server using conect(), i then do any of the other functions and it will say that $fp is not a valid stream resource. I think that when i make the connection to the server it declares $fp as the socket connection only within the function, how can i solve this problem
p.s feel freee to use this code