I am having trouble with the following script:-
[code=php]
<?php
//function to send back to view
function post($host, $path, $data) {
$http_response = '';
$content_length = strlen($data);
$fp = fsockopen($host , 80);
fputs($fp, "POST $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: $content_length \r\n");
fputs($fp, "Connection : close\r\n\r\n") ;
fputs($fp, $data);
while (!feof($fp)) $http_response .= fgets($fp, 1024);
fclose($fp);
return $http_response;
}
// get all post data
$postdata = 'foo=bar';
foreach($_POST as $key => $val) $postdata .= '&'.$key.'='.$v al;
// send post data to function post()
post('www.stirf ie.com', '/view.php', $postdata);
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitl ed Document</title>
</head>
<body>
<?php
echo "$http_response ";
?>
</body>
</html>
the page view.php is :-
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>test post</title>
</head>
<body>
<?php
$info = $HTTP_POST_VARS ;
foreach( $info as $key => $value){
echo $key . ':' . " \t$value<br>";
}
?>
</body>
</html>
[/code]
the fgets is not retreiving the form data from view.php, can any one tell me where I am going wrong. I would eventually like to write my own ipn, but at the moment I am just experimenting with sockets.
Regards
Stirfie
[code=php]
<?php
//function to send back to view
function post($host, $path, $data) {
$http_response = '';
$content_length = strlen($data);
$fp = fsockopen($host , 80);
fputs($fp, "POST $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: $content_length \r\n");
fputs($fp, "Connection : close\r\n\r\n") ;
fputs($fp, $data);
while (!feof($fp)) $http_response .= fgets($fp, 1024);
fclose($fp);
return $http_response;
}
// get all post data
$postdata = 'foo=bar';
foreach($_POST as $key => $val) $postdata .= '&'.$key.'='.$v al;
// send post data to function post()
post('www.stirf ie.com', '/view.php', $postdata);
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitl ed Document</title>
</head>
<body>
<?php
echo "$http_response ";
?>
</body>
</html>
the page view.php is :-
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>test post</title>
</head>
<body>
<?php
$info = $HTTP_POST_VARS ;
foreach( $info as $key => $value){
echo $key . ':' . " \t$value<br>";
}
?>
</body>
</html>
[/code]
the fgets is not retreiving the form data from view.php, can any one tell me where I am going wrong. I would eventually like to write my own ipn, but at the moment I am just experimenting with sockets.
Regards
Stirfie
Comment