PHP & Sending post data VIA fsockopen()... Problems...
Posted: Wed Jun 04, 2003 12:59 pm
I've been working on a overlay for a old UBB board, and I'm trying to post to it from a php script I wrote. Here are the functions...
The script is not returning any errors, nor can I see any, but it really isn't doing or returning ANYTHING. the target forum for this experiment is http://www.cognitoy.com/cgi-bin/forumdi ... s&number=3
I built the request by looking over the new topic form. Got the IP by trying to D/L a page with FlashGet.
I get no response from the script at all.
As you might have noticed, this is actually run with php-gtk (I'm having lots of success with it...), latest version of php. mrbb_make_topic() is called via a button currently. I know the code executes, becase it required a little debugging to get no error responses O.o Please help ASAP...
The script is not returning any errors, nor can I see any, but it really isn't doing or returning ANYTHING. the target forum for this experiment is http://www.cognitoy.com/cgi-bin/forumdi ... s&number=3
I built the request by looking over the new topic form. Got the IP by trying to D/L a page with FlashGet.
I get no response from the script at all.
Code: Select all
<?php
function send_headers ($fp) {
fputs ($fp, "Accept: */*\n");
fputs ($fp, "Accept-Language: en\n");
fputs ($fp, "Connection: Keep-Alive\n");
fputs ($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\n");
}
// post data and return reply
function post_data ($host, $url, $data) {
$fp = fsockopen ($host, 80, $errno, $errstr, 120) or die($errno.$errstr);
$ret = "";
if (strncasecmp ($url, "http://", 7) == 0) $url = substr ($url, 7);
$p = strpos ($url, '/');
if (empty ($p)) {
$req = "/";
} else {
$req = substr ($url, $p);
}
if ($fp) {
fputs ($fp, "POST $req HTTP/1.0\n");
send_headers ($fp);
fputs ($fp, "Content-type: application/x-www-form-urlencoded\n");
$out = "";
while (list ($k, $v) = each ($data)) {
if(strlen($out) != 0) $out .= "&";
$out .= rawurlencode($k). "=" .rawurlencode($v);
}
$out = trim ($out);
fputs ($fp, "Content-length: ".strlen($out)."\n\n");
fputs ($fp, "$out");
fputs ($fp, "\n");
while(!feof($fp)){
$ret .= fgets($fp,128);
}
fclose ($fp);
}
return $ret;
}
function mrbb_make_topic($forum, $user, $pass, $topic, $msg) {
$forum_number = array(
'New Player Discussion' => 1,
'Advanced Player Discussion' => 2,
'Questions/Comments' => 3,
'Bug Report Forum' => 4,
'New Component Ideas' => 5,
'New Scenario Ideas' => 6,
'Contests' => 8,
'ICE SDK' => 9,
'MindRover and Robotics' => 12,
'5 Card Dash' => 13
);
$forumn = $forum_number{$forum};
$post = array(
'action' => 'posttopic',
'forum' => $forum,
'number' => $forumn,
'UserName' => $user,
'Password' => $pass,
'MsgIcon' => 1,
'Message' => $msg,
'TopicSubject' => $subject,
'Signature' => 'yes'
);
$ret = post_data("66.70.176.91", "/cgi-bin/postings.cgi", $post);
return $ret;
}
function mrbb_make_topic2() {
$tatm = "This is Sky. Hi all (Sorry for any annoyances, Kent/Nat).
This has been posted from my app, on my pc. Interface isn't made yet, but we'll see...
--Sky";
mrbb_make_topic('Questions/Comments', $user, $pass, 'TepApp Test', $tatm);
}
?>