Forum Moderators: coopster

Message Too Old, No Replies

is this script written correctly?

simulate form post error: getaddrinfo failed

         

verb

3:14 pm on May 11, 2005 (gmt 0)

10+ Year Member



I have a form on my website that creates cookies in the header when the page loads. I am attempting to mimic a form post.

I get the following 2 errors when tring to simulate the post:

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/html/postit2.php on line 60

Warning: fsockopen(): unable to connect to http::80 in /var/www/html/postit2.php on line 60
Error 0 Success

The initial code on my page with the data I want to automatically send to my form is

 

include("postit2.php");

require_once "HTTP/Request.php";

$req =& new HTTP_Request(" http://www.abc.com/page.php");

$data["dbType"] = "mysql";
$data["dbHost"] = "localhost";
$data["dbUser"] = "#*$!";
$data["dbPass"] = "letmein";
$data["dbName"] = "me";

$result = post_it2($data, " http://www.abc.com/page.php");

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];

}

?>

the php file with the function info that should submit the form is:


<?php

function post_it2($data, $URL) {

// Strip http:// from the URL if present
$URL = ereg_replace("^http://", "", $URL);

// Separate into Host and URI
$Host = substr($URL, 0, strpos($URL, "/"));
$URI = strstr($URL, "/");

// Form up the request body
$ReqBody = "";
while (list($key, $val) = each($data)) {
if ($ReqBody) $ReqBody.= "&";
$ReqBody.= $key."=".urlencode($val);
}
$ContentLength = strlen($ReqBody);

// Generate the request header
$ReqHeader =
"POST $URI HTTP/1.0\n".
"Host: $Host\n".
"User-Agent: PostIt\n".
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: $ContentLength\n\n".
"$ReqBody\n";

// echo $ReqHeader;

// Open the connection to the host
$socket = fsockopen($Host, 80, &$errno, &$errstr);
if (!$socket) {
$Result["errno"] = $errno;
$Result["errstr"] = $errstr;
return $Result;
}
$idx = 0;
fputs($socket, $ReqHeader);
while (!feof($socket) && $Result[$idx-1]!= "0\r\n") {
if (substr($Result[$idx-1], 0, 2) == "0\r\n") echo "The End:".strlen($Result[$idx-1]);
$Result[$idx++] = fgets($socket, 128);
}
return $Result;
}
?>

why do I get the two errors above? Is it because I am suppose to send the cookies back in the form somehow?

The name of the cookie is PHPSESSID I believe

I have read an article on zend dot com about mimicking submission posts and am still lost. Any help given would be greatly appreciated.

Thanks

[url] [zend.com...] [/url]

coopster

11:23 pm on May 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, verb.

There is only one variable on that line that could be giving you a problem, $Host. At least that's what it seems to me. Did you try dumping that variable to the browser and see if it is what you expect?