Hey dude,
In my last job I was head of 3 departments, before that various shades of programming manager for years, a development dude for many years before that. I've probably hired, trained, managed and groomed more professional coders than you've known in your life, even though you claim 37 years of coding.
I know how to read the manual, I even know the URL for php.net. Further, I went as far as to publish my own devised method for accomplishing the task and was clearly asking if there was a
better way, not just a
different and completely less elegant way. I stopped in, registered and asked for help because I was googling this problem and found this thread with a very similar situation. I was hoping the person giving advice was actually qualified.
You sent me to a completely bull.... site with bad examples, no useful commentary, specifically didn't answer my question and did exactly what I stated I didn't want to do. Tell me, how were you helpful? ..and now you're offended because I called you on it?
I can read the manuals, and I can assemble a series of php functions that will get the job done, but I'd to see some examples from others in how they would accomplish such a task, because over the years I've actually learned that I'm not always right.
Not insignificantly, curl will almost certainly not be installed, compiled into php, or available to be used on all of my client's machines.
Finally, If you just want to be an index for wikipedia, how about posting a link to something of quality like this?
[php]//Here's a slightly modified version of sendtohost():
/* sendToHost
* ~~~~~~~~~~
* Params:
* $host - Just the hostname. No http:// 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;
}[/php]
Source:
http://www.faqts.com/knowledge_base/...id/12039/fid/5
Or perhaps something like this:
[php]
<?php
function post_it($datastream, $url) {
$url = preg_replace("@^http://@i", "", $url);
$host = substr($url, 0, strpos($url, "/"));
$uri = strstr($url, "/");
$reqbody = "";
foreach($datastream as $key=>$val) {
if (!is_empty($reqbody)) $reqbody.= "&";
$reqbody.= $key."=".urlencode($val);
}
$contentlength = strlen($reqbody);
$reqheader = "POST $uri HTTP/1.1\r\n".
"Host: $host\n". "User-Agent: PostIt\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: $contentlength\r\n\r\n".
"$reqbody\r\n";
$socket = fsockopen($host, 80, $errno, $errstr);
if (!$socket) {
$result["errno"] = $errno;
$result["errstr"] = $errstr;
return $result;
}
fputs($socket, $reqheader);
while (!feof($socket)) {
$result[] = fgets($socket, 4096);
}
fclose($socket);
return $result;
}
?> [/php]
USING THE FUNCTION:[php]<?php
$data["foo"] = "some";
$data["bar"] = "data";
$result = post_it($data, "http://www.zend.com/test/test.php3");
if (isset($result["errno"])) {
$errno = $result["errno"];
$errstr = $result["errstr"];
echo "<B>Error $errno</B> $errstr";
exit;
} else {
for($i=0;$i< count($result); $i++) echo $result[$i];
}
?> [/php]
Source:
http://www.zend.com/zend/spotlight/mimocsumissions.php
But like I said, I was looking for an
elegant solution.
So, do you understand my unhappiness at your response?
Good luck in your endeavors.
Ron.