I try to open another server by using fsockopen function. I need to LOGIN and POSTING my news data.
I sucessfully login but have problem when posting the data, because the session_id is DIFFERENT when login and posting the data. So when i post the data, the server ask me to login again 🙁
I used below code to login:
<?
function sendToHost($host,$method,$path,$data)
{
// Supply a default method of GET if the one passed was empty
if (empty($method))
$method = 'GET';
$method = strtoupper($method);
$fp = fsockopen($host,80);
if ($method == 'GET')
$path .= '?' . $data;
fputs($fp, "$method $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: " . strlen($data) . "\n");
fputs($fp, "Connection: close\n\n");
if ($method == 'POST')
fputs($fp, $data);
while (!feof($fp))
echo fgets($fp,1024);
fclose($fp);
}
$login=sendToHost('www.test.com','post','/go.php?action=login','user=myuser&pass=mypass');
$postdata=sendToHost('www.test.com','post','/go.php?action=postdata','data=this is my news');
?>
The script above sucess only when login buat failed when posting news data. I need help from you guys, how to LOGIN and POSTING news data with fsockopen in better way?
Thanks so much with your help! 🙂