Hello.
I need to write a script posting data to a site in such form
<form action="PutPost.phtml" method="POST">
<table cellspacing="0" cellpadding="2" border="0" width="100%" bgcolor="#000000">
<tr>
<td valign="TOP" width="30%">
<b>
<input type="radio" name="PostType" value="1" >P1<br>
<input type="radio" name="PostType" value="2" checked>P2<br>
<input type="radio" name="PostType" value="3" >P3<br>
<input type=Hidden name=tpass value="150ad09621c283d05641a2eebb91f545dfbf0ef">
<input type="radio" name="PostType" value="4" >P4
</b>
</td>
<td align="RIGHT">
<textarea name="Postbody" cols="68" rows="5" wrap="VIRTUAL"></textarea>
</td>
</tr>
<tr>
<td valign="TOP" colspan="2">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left">Name<input type="Text" name="PostMenName" size="20" maxlength="20" value=""></font>
</td>
<td align="left">Email:<input type="Text" name="PostMenMail" size="20" maxlength="35" value=""></font>
</td>
<td align="RIGHT"><font size="2"><input type="Submit" name="submiting" value="SUBMIT" align="Left"></font></td>
</tr>
</table>
</td></tr></table></form>
I have a function for working with POST method.
/ sendToHost
* Params:
* $host - Just the hostname. No [url]http://[/url] or
/path/to/file.html portions
* $method - get or post, case-insensitive
* $path - The /path/to/file.html part
* $data - The query string, without initial question mark
* $useragent - If true, 'MSIE' will be sent as
the User-Agent (optional)
*
* Examples:
* sendToHost('www.google.com','get','/search','q=php_imlib');
* sendToHost('www.example.com','post','/some_script.cgi',
* 'param=First+Param&second=Second+param');
*/
function sendToHost($host,$method,$path,$data,$useragent=0)
{
// 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\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp,"Content-type: application/x-www-form- urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
if ($useragent) {
fputs($fp, "User-Agent: MSIE\r\n");
}
fputs($fp, "Connection: close\r\n\r\n");
if ($method == 'POST') {
fputs($fp, $data);
}
while (!feof($fp)) {
$buf .= fgets($fp,128);
}
fclose($fp);
return $buf;
}
Problem for me is textarea in a form. How can I send data from textarea to site accordingly to sendtohost function. There are many line in a textarea dividual by enter.